SharePoint Designer — Custom activity to execute user-defined C# functions

 

UPDATE: This has been released to CodePlex here: http://www.codeplex.com/spdwfextensions

UPDATE: See here for latest release notes: http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!381.entry

UPDATE: See here for my thoughts on commercializing this project: http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!569.entry

This project provides a custom activity in SharePoint Designer.  Use this custom activity to invoke (dispatch) any C# function that you incorporated into the linked assembly.

As of late October, 2007, this is just an initial version of the project.  I plan to expand it with a number of additional functions, including substring, index, replace, invoking web services and anything that seems useful or interesting.  I also plan to post this to codeplex once I have my act together on that front.  This will also be deployable as a solution at some point.

If you have any comments, questions or suggestions, please leave them in comments or email me.

Disclaimer:

I make absolutely no claims as to the suitability of this for any purpose.  Use at your own risk.

Installation steps (to be followed for each WFE in the farm):

1. Download the .zip and extract.

2. Install the .dll into the GAC.  I usually open c:\windows\assembly using windows explorer and copy it there.

3. Modify web.config to add the assembly to the safe controls:

<System.Workflow.ComponentModel.WorkflowCompiler>
  <authorizedTypes>

<authorizedType Assembly="SpdGenericInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=abe076fd8125f3c4" Namespace="Nivlag" TypeName="*" Authorized="True" />

4. Copy "SpdGenericInterface.actions" to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\Workflow

Note that the above location is specific to english language installations.

5. Close SharePoint Designer (if it’s already open).

6. iisreset

7. Open SPD and create a new workflow.

If all goes well, you should be rewarded with a new category of action:

image

 

Notes:

See here (http://blogs.msdn.com/sharepointdesigner/archive/2007/03/15/adding-activities-to-spd.aspx) for a terrific overview of the process for creating, installing and configuring a solution like this.

The .zip is designed to extract directly to you c:\ drive.  If you do this, you can open the project and all the paths will be consistent.

To use this in visual studio, you probably need to install "Extensions for Windows WF".

The initial upload contains just one "dispatcher function", "ToLower()".  To add more functionality, add it to the Execute method as shown:

 protected override ActivityExecutionStatus
          Execute(ActivityExecutionContext executionContext)
        {

            string functionToDispatch;
            functionToDispatch = this.DispatchFunction.ToLower();

            switch (functionToDispatch)
            {
                case "tolower()":
                    {
                        this.OutResult1 = this.InParam1.ToLower();
                        break;
                    }

                default:
                    {
                        this.OutResult1 = "Unknown function: [" + this.DispatchFunction + "].";
                        break;
                    }
            }

            return ActivityExecutionStatus.Closed;
        } // ActivityExecutionStatus

    }

Then, re-build the project and copy the assembly to the GAC.  I expect an iisreset would be required.

9 thoughts on “SharePoint Designer — Custom activity to execute user-defined C# functions

  1. Gerry Whitworth
    I followed his directions and everything seemed to work until I choose the action in SP Designer.  The designer did not paste the code in the workflow.  I sent this guy an email and I guess he is too busy to respond. 
     
    I solved the problem myself.
     
    Past the actions from "SpdGenericInterface.actions" into the "WSS.actions" file and it everything worked.  I hope this helps others.
    Reply
  2. Marco mancinelli
    it sounds good, but I can’t install the extension =(
    my Designer con see it but when i click on it nothing appear… please help… tnx.
    Reply
  3. Bernard Lambeth

    I’m using this custom activity to Replace() function. The farm is SharePoint 2007, with load-balanced web front-ends. I am getting intermittent failure to start errors, but the workflows usually restart in 5 – 15 min. I believe the timer jobs Workflow and Workflow Failover are restarting the workflows. I reviewed the SharePoint logs, and finally caught this error.

    RunWorkflow: Microsoft.SharePoint.SPException:
    at Microsoft.SharePoint.Workflow.SPNoCodeXomlCompiler.LoadXomlAssembly(String assmNameIn, SPWeb web)
    at Microsoft.SharePoint.Workflow.SPWinOeHostServices.CreateInstance(Guid trackingId, SPWorkflow workflow)
    at Microsoft.SharePoint.Workflow.SPWinOeEngine.RunWorkflow(Guid trackingId, SPWorkflowHostService host, SPWorkflow workflow, Collection`1 events, TimeSpan timeOut)
    at Microsoft.SharePoint.Workflow.SPWorkflowManager.RunWorkflowElev(SPWorkflow originalWorkflow, SPWorkflow workflow, Collection`1 events, SPRunWorkflowOptions runOptions)

    I found a reference to this error on another blog, http://www.kentd.com/index.php/all-blog/218-nivlag-and-spdgenericinterface. The author indicated he was using the custom actitivity Replace(), as well. Have you seen this error? Do you have any suggestions on how to resolve it?

    Reply
    1. Paul Galvin Post author

      Sorry I never responded. At thi’s point, it’s probably moot. I hope you were able to resolve it.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *