Category Archives: SharePoint Developer Productivity Tip

Tip: Debugging Feature Event Receivers in SharePoint Sandbox Solutions

I accidently discovered this yesterday and thought I’d share. If only this same technique worked with farm solutions…

If you’ve done any sandbox development you have probably had many moments when you pressed F5 to start debugging or done Build|Deploy only to see a failure because one of your feature receivers threw an error. To debug these problems in farm mode, you attach the debugger and then try to activate the feature via the site, PowerShell, or stsadm. It’s kind of a pain.

In sandbox mode, if you attach the debugger to the worker process manually before you deploy the solution you can catch and debug problems in your feature event receivers. To do so, select Debug|Attach to process and attach to SPUCWorkerProcess.exe.

Then, simply hit F5 or select Build|Deploy Solution. I wish I’d figured this out a year and a half ago. It would have saved me a great deal of time!

Happy coding!

Author: Doug Ware

SharePoint Developer Productivity Tip #3 – Easy CAML Queries

Previously, I wrote about CAML queries and the CAML Query Builder. I no longer use this tool. This is not because of any lack in the tool but rather a desire to simplify my development environment – a shift away from many specialty tools to a few generalized ones. Chief among these is SharePoint Manager 2007. In the previous productivity tip, I talked about using SPM to extract site columns for features (you can do something similar for content types with a bit more effort). This one is about CAML queries.

To get the syntax for a CAML query, I start by creating a view of the list that has the same structure as the ultimate target of the query. For example, I have a calendar, and I’d like to create a query of my upcoming (and sorely needed) vacations. I start by creating a new Calendar list to act as a prototype. Next, I create a new view with the desired set of fields and whatever sort, filter, and grouping I desire.

Once I have the view, deriving the CAML query from it with SPM is easy. I simply navigate to the view and copy the query and ViewFields from the Schema XML tab!


Author: Doug Ware

SharePoint Developer Productivity Tip #2 – Easy Site Column Features

Almost every SharePoint project involves custom site columns. You can create a site column via the browser, but unless the column is trivial and only used in a single site, you should always deploy site columns using features. The reason for this is that when you create a site column via the browser, SharePoint always creates a new globally unique identifier. If you create a site column with the browser on one site, and then repeat the work on another site, you will have two unique site columns because even though the site columns on both sites are otherwise identical, they have different ID’s.

The different IDs are a problem if you ever need to aggregate the data across the site collections, if you want to use the column in search scopes, and if you are using records center. Even if you have none of these needs, you certainly don’t want to have to create the same site column by hand over and over again on every site where it is needed. And, if your solution requires any custom site columns, it probably requires many of them.

The features schema for site columns, or Fields, isn’t trivial. You can see it here: . I could create my <Field> definitions by hand, but I am much too lazy for that! The browser makes it so easy! Fields in the SharePoint object model are handled by the SPField class. The SPField class has a property, SchemaXml, which contains the XML definition for the field. This XML is exactly the same as the XML required in a feature’s element manifest to define the field.

The fastest and easiest way to make a site column feature is to:

  1. Create the site column on a development site in the browser.
  2. Use a tool to copy the resulting SPField instance’s XmlSchema property value.
  3. Paste it into your element manifest.

It doesn’t get much easier than copy and paste. There are a number of tools out there that you can use to do this, but the one I use is SharePoint Manager 2007 by Carsten Keutmann. Carsten is also the creator of WSPBuilder and I am a big fan of his work. I use the free SharePoint Manager 2007 for many different tasks, some of which I will write about in subsequent SharePoint Developer Productivity Tips!

To get the SchemaXml, simply navigate to the field in SharePoint Manager 2007, select the Schema Xml tab, and copy the text.

Here is the copied schema from the core About Me site column:






DisplayName="About Me"






FromBaseType="TRUE" />

Author: Doug Ware

SharePoint Developer Productivity Tip #1 – Visual Studio Project Templates

At the second meeting of the new Atlanta SharePoint User Group, Dan Attis spoke on SharePoint development environments. His talk reminded me that I have meant for some time now to post a series about specific techniques that I use to make life as a SharePoint developer more productive. This post is the first in a series and it covers the subject of project templates.

I use a project template that allows creation of Web Forms and Controls with the visual designer, is configured for WSPBuilder and code signing, and has some standard assembly references. If you aren’t interested in the details of how to make your own, you can just download mine from here ( and place it into your DocumentsVisual Studio 2008TemplatesProjectTemplates folder or you can keep reading!

A Visual Studio project template defines the base configuration of a new project. If you’ve ever used VS, you have used a project template. When I am starting from scratch, I usually use the C# Class Library project template because it makes the fewest assumptions about what I am doing and therefore imposes the fewest restrictions. One problem with this approach is that the Class Library template lacks the item templates for ASP.NET. Among these are the templates for Web Forms and User Controls. I like the productivity tools provided by these item templates, especially the visual designers. Fortunately, it is easy to add the Web Form and User Control item templates to a Class Library!

In Solution Explorer, right-click the project node and choose Unload Project to expose the project file for editing and then edit the file.

The file opens in the editor. Insert the <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids> element beneath <ProjectGuids> element and save the file.

Right-click the project in Solution Explorer and select Reload Project. Now when you add a new item to the project you have the option to include any of the standard ASP.NET Web items.

I use the WSPBuilder tool to create web solution packages that I can install and deploy on SharePoint farms. WSPBuilder is simple to use, but it requires that the project files are in folders within the project that match the deployment target’s structure (the 12 hive). The next step is to create the folders shown below.

When you run WSPBuilder it creates a solution manifest based on the files that are actually in the project. So, if I don’t include any files in a particular folder, the presence of the folder in the solution won’t affect the package. So, I usually just start out with the set of folders I am most likely to use ahead of time.

Most projects require a few feature receivers or other code that has to deploy to the Global Assembly Cache. This requires that the assembly has a strong name, which in turn requires a strong-name key. The next step is to configure code signing. You can read more about that process here:

WSPBuilder will also specify in the solution manifest that the assembly should deploy to the GAC if it finds it in a GAC folder beneath the project root. To enable this create the folder in the project and set the output path. To learn how to do this, see: At this point, the project structure looks like the following:

Finally, before I can write any code, I need to add references to the SharePoint and various System.Web assemblies.

That’s a lot of work to go through every time I want to create a new solution. In a team environment over the course of a year you could waste days doing this by hand. Worse, different members of the team might do things differently resulting in confusion for all. If you save the result as a project template you can avoid ever having to do these steps again. You can also share the template with your teammates. To export the project as a template, select File|Export Template and complete the wizard. The result is a ZIP file. If you give it to a teammate and they put it into their DocumentsVisual Studio 2008TemplatesProjectTemplates folder, they will have it as an option when they create a new project.

You can download the result here:

Author: Doug Ware