Common Pitfalls in SharePoint Designer Custom Actions

I crafted a handful of custom workflow actions for SharePoint Designer recently and I noticed several recurrent errors:

  • When you select a custom activity from the Actions drop-down, nothing happens
    • Usual suspect: the class name and assembly reference do not match in ACTIONS file and DLL. Please check that your class reference in the Action tag in the ACTIONS file exactly matches your DLL full name.
    • Not so usual suspect: SPD has a cached reference of your old DLL. Exit SPD, delete ApplicationDataMicrosoftWebSite Cache folder and restart SPD.
    • Even less usual suspect: You’ve correctly placed the ACTIONS file and the activity DLL, but you haven’t added an authorizedType element into your web application web.config file. Add the correct entry (you can check the whole process here) and try again.
  • When you bind a property to a value, it doesn’t get set
    • Usual suspect: the demoted property name in your DLL and in ACTIONS file do not match. Please check that all your properties in the code exactly match the Parameters section elements in your ACTIONS file.

I hope that these simple advices save you valuable time. Happy programming in the WF world!

Email a Link to the Current List Item from SPD Workflow

If you use the built-in activity of SharePoint Designer workflow “Send email”, you can embed the URL of the current item (“Absolute Encoded URL”). However, this approach makes a URL of this kind

http://server/site/Lists/listname/1_.000

which is wrong.

The workaround is to use the SharePoint DispForm.aspx page and append an ID from the current item:

http://server/site/Lists/listname/DispForm.aspx?ID=[%ListItem:ID%]

(of course, being ListItem your own list name in SharePoint Designer)

Patch for SharePoint Workflow Time-based Activities

Today I’ve been working on a “Early Warning” workflow designed with SharePoint Designer. It is supposed to run on every item change and to suspend itself until few days before item’s expiry date (it’s just a date column). But, it didn’t work as expected.

I remembered reading that there are some glitches in the way Workflow Foundation dehydrates and rehydrates the “sleeping” workflows. There is a patch available at http://www.microsoft.com/downloads/details.aspx?FamilyID=6096ce0f-d21e-47ac-afe2-d4e1c2fce670&displaylang=en.

I downloaded it and it worked like a charm!

Community Kit for SharePoint 2.0 Pre-Release

Exciting news! The CKS 2.0 has been pre-released. It’s just been a few months since the project started and we already have something tangible.

The features included in this pre-release are:

Enhanced Blog Edition Beta 1
Enhanced Wiki Edition Alpha
ChatterBox AJAX Beta
Tag Cloud

Download any of the components above and play with them (not in production environment, though)…and, above all, provide feedback to the team.

Full announcement can be found here.

Community Kit for SharePoint


Few months ago I joined Community Kit for SharePoint team. It’s a collaborative open-source effort to extend and adapt SharePoint for different communities. This project is led by Lawrence Liu, Senior Technical Product Manager and Community Lead at Microsoft (his blog runs on SharePoint). It’s hosted on CodePlex, at http://www.codeplex.com/CKS.

Right now there are different editions in progress:

I’m collaborating in Corporate Intranet and Internet/Extranet edition as a developer. I’ll publish news from this project on a regular basis.

Stay tuned for much more free releases from CKS project very soon. If you would like to contribute, please visit the project page and see where you can help.

How to Optimize SharePoint Designer’s Use of Content Types in a Workflow

I’m annoyed by many little details of the SharePoint Designer Workflow editor, but the main one is that it profligates in the creation of content types. It creates one content type for any custom form that you create when collecting data from a task. Moreover, it doesn’t give you the chance to reuse an existing type….every new task is a new content type in the Tasks list.

However, you CAN reuse existing content type for the Tasks list. You just have to create the first form as usual and then create a second form with a easy-to-find name such as “DUMMY”. Then, a little bit of manual work follows:

  • Open the XOML file of your workflow with right click, choosing “Open With” then “SharePoint Designer (Open As XML)
  • Find the first “CollectDataTask” action, such as this one

    <ns0:CollectDataTask x:Name=”ID15″ ContentTypeId=”0x01080100AC1C1A96057F4B4897ED6C99E92728F500A85399B392A23943B207F10B3F8BB318″ TaskId=”{ActivityBind ROOT,Path=taskAM}” Title=”CAF Approval 1″ InProperties=”{x:Null}” __Context=”{ActivityBind ROOT,Path=__context}” OutProperties=”{x:Null}” AssignedTo=”{ActivityBind ROOT,Path=userAM}” />

  • Copy the line after the x:Name field
  • Find the CollectDataTask with the Title=”DUMMY”
  • Replace the content of the line after the Name field with the first action copied data

That’s it! Now you can safely remove the DUMMY content type from the Task list and Site Content Types list.

SharePoint Hotfix is available

Microsoft released, at least, a quick-and-dirty hotfix that fixes up several issues with SharePoint Services 3.0.

In particular, I’ve found one of the issues to be very annoying. Namely, when you create a site and customize a list view to something other that the default view and then save the site as a template, these changes are not saved. So, when you create another site based on this template, the list view you customized reverts to the default view.

Among other issues, this is solved in the Hotfix that can be found on this address: http://support.microsoft.com/default.aspx?scid=kb;EN-US;934790

Well…now we have to wait for the SP1 to become available…..I hope it will be this year.

COM Again (0x81020037)

I found this “descriptive” error message in a fragment of MOSS 2007 code in a webpart that uploads and tags a document with appropriate metadata:

Microsoft.SharePoint.SPException: DOMAINuser has modified the file Sample.doc
System.Runtime.InteropServices.COMException (0x81020037)

The code 0x81020037 is “Save Conflict” error code in COM. The culprit:

SPListItem doc = list.Add();
doc[“Field1”] = “Value”;
doc[“Field2”] = “Value”;
doc.CheckIn(“Check-in Message”);
doc.Update(); <-- this is the line that throws the error I tried reversing CheckIn and Update methods, with no success. However, the following trick did the job: SPListItem doc = list.Add();
doc[“Field1”] = “Value”;
doc[“Field2”] = “Value”;
doc.CheckIn(“Check-in Message”);
doc = FindByTitle(doc.Title)
doc.Update();

FindByTitle is a custom method I wrote that finds a SPListItem in a SPList, performing a search on the Title field.

The explication: the underlying COM scaffolding doesn’t like the Update() method after CheckIn(). I had to “reacquire” the item and perform the Update() on this new reference to the same document.

Elementary, dear Watson….

Authentication when consuming a web service with Integrated Authentication

The most convenient way is to pass the user credentials from the client to the web service, providing a DefaultCredential object to the Credentials property of the web service proxy:

ws.Credentials = System.Net.CredentialCache.DefaultCredentials;

before invoking the web service.

How to Serialize a Collection

In a fragment of a code I’m working on, I must serialize a collection of links into an XML file. Fortunately, .NET Framework provides a quick XmlSerializer class to do the dirty job for you.

Well, almost…

The problem

If you try to serialize a class derived from CollectionBase, the Serialize method will throw a nasty exception.

The workaround

Use a container class, put the CollectionBase-derived class as a property, decorate this property with XmlArray and XmlArrayItem tags.

[Serializable]

public class CollectionContainer

{

private LinkCollection _links= new ColeccionEnlaces();

[XmlArray(“Links”)]

[XmlArrayItem(“Link”,typeof(Link))]

public LinkCollection Links

{

get

{

return _links;

}

set

{

_links = value;

}

}

}