January 3, 2012

Problem with Risks and Issues in PWA for Project Server 2010 after upgrading from 2007

This is an issue I came across after upgrading our SharePoint and Project Server 2007 environment into SharePoint and Project Server 2010.

Issue

Any updates made to the Risks or Issues lists in the Project Workspace (PWS) were not being carried over from PWS to the  Project Web Application (PWA)

PWS Risks List:

image

PWA Issues and Risks Page:

image

You will notice that the Active, Postponed, and closed count is not correct. If you go to SharePoint Logs, you will find a critical error complaining about references to the old Project Server assembly, viola!

Error

01/03/2012 14:11:14.59     w3wp.exe (0x246C)                           0x1860    SharePoint Foundation             General                           6644    Critical    Event manager error: Could not load file or assembly 'Microsoft.Office.Project.Server.PWA, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.    

Solution

I noticed that all the event receivers linked to those two lists are still referencing Version=12 assembly and not the new Version=14.

To resolve this issue, update all the event receivers to reference Assembly: Microsoft.Office.Project.Server.PWA,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c

You are welcome!

December 20, 2011

Error When Deploying a Custom Solution in SharePoint 2010

This is an error I received when trying to deploy a SharePoint 2010 with a custom site definition in my development environment

Error

"PMS_FG" and "PMS_FG" contain a file that deploys to the same Package location: PMS\PMS_FG\documents.aspx    D:\Users\dalzoubi\Solutions\PMIS\Spectra.PMS2010\Package\Package.package

image

Looking at the folder PMS_FG\, there is only one document.aspx file!!!

image

So that did not make sense at first site, so  I decided to open the Visual Studio Project Item Data file that represents the site definition to see what is going wrong in there.

Solution

1. In Solution Explorer, right click the Site Definitions and click Open Folder in Windows Explorer

image

2. In explorer view, double click SharePointProjectItem.spdata, select Select a program from a list of installed programs, click OK

3. Select Notepad, uncheck Always use the selected program to open this kind of file.

4. Click OK

5. Notepad opens and right there you will notice one element that is different than the other elements:

image

6. Remove that element, Save and close your file.

image

7. Go back to Visual Studio, you will be asked to reload that file, click Yes to All

image

8. Now try to deploy your solution, you should no longer have that error.

Happy coding!

September 28, 2011

Console application with SharePoint client object model crashes when run remotely

So I started experimenting with the new client object model that comes with SharePoint 2010. I created a console application that references Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll to use the capabilities of this object model.
I created an application that simply looks at one of the lists on my root site and prints out the list name, COOL app huh!
using System;
using System.Net;
using Microsoft.SharePoint.Client;
 
namespace SharePointTest
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                var credential = new NetworkCredential("user", "pass", "domain");
                var clientContext = new ClientContext("http://sp2010") {Credentials = credential};
                Web web = clientContext.Web;
 
                List projects = web.Lists.GetByTitle("Projects");
                clientContext.Load(projects);
                clientContext.ExecuteQuery();
                Console.WriteLine("List name: {0}.", projects.Title);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }
    }
}
Worked like a charm on my virtual development box that has SP2010 installed on it. So I decided to move it to my Win7 environment to see if it does what it claims to do (which is run remotely!). To come to a surprise that application crashes! even when wrapping my code with Try Catch blocks.

Issue

Console application with SharePoint client object model crashes when run remotely.

Solution

Register Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll in GAC on the remote computer where you like to run your application that references the above assemblies.

September 18, 2011

One Issue with Web.Fields.Add in SharePoint 2010

I was trying to add a field, and for the heck of it, I decided to start with a field name that has spaces in it:
string benefitsLongDesc = web.Fields.Add("Benefits Long Description", SPFieldType.Note, false);
web.Update();

SPField benefitsLongDescField = web.Fields[benefitsLongDesc];
benefitsLongDescField.Title = "Long Description";
benefitsLongDescField.Group = "Human Resources";
benefitsLongDescField.Update();

I was surprised that code line 4 failed to resolve field, even when I’m returning the internal field name from code line 1.

To resolve this, you have a couple of options:
  1. Don’t use spaces in the Display Name in code line 1, which is preferred as you don’t want your field internal name to contain spaces that get converted to _x0020_ and make your life miserable trying to remember to add those characters every time you want to call the field.
  2. In code line 3, instead of getting the field from web.Fields directly, use the following:
SPField benefitsLongDescField = web.Fields.GetFieldByInternalName(benefitsLongDesc);
Happy coding!

May 19, 2011

When not to use SPContext.Current.Web

This morning I was trying to change a title of a webpart that I have in my SharePoint site, when I noticed that its not working and throwing the following error

Cannot save the property settings for this Web Part. Exception occurred. (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))

image

I was surprised since nothing much has changed in that page since the last time we created it!

So I started looking for an answer, and as usual the first spot was the SharePoint logs and that proved useless as it only showed the error message that the webpart was displaying, duh!

Next step was to run Visual Studio in debug mode to see if I can catch any exceptions on the page that our custom webparts may have caused, and that didn’t work either.

the final step was to remove the webparts of the page one by one to see which one was causing the issue and viola! When removing the webpart, the error disappeared for all the other webparts. So I decided to open up Visual Studio again and inspect the code for that webpart.

This webpart was doing a lot of things, but one thing I have noticed was the use of SPContext.Current.Web in one of the methods and while I was searching the web for an answer, some people mentioned that this call causes issues, so I replaced that call with using (SPWeb web = SPContext.Current.Site.OpenWeb()) and that worked! Unbelievable.

Lessons learned: do not use SPContext.Current.Web  or even SPControl.GetContextWeb(Context) in your webparts as that causes issues with the webpart page.