January, 2010

  • Visual Studio SharePoint Development Blog

    Creating SharePoint items with CreateItemActivity


    Instead of creating new list items from code in your workflow you can use CreateItemActivity. CreateItemActivity can be used for creating list items or files. Properties of interest for this activity are the following (most of them are self-explanatory):

    Property Name



    WorkflowContext object.


    Properties of a new item.


    List ID or list name where new item will be created.


    New item ID is stored in this property.


    Set to true if you want to overwrite existing items.

    In order to use CreateItemActivity (or any other *ItemActivity from the toolbox such as CheckInItemActivity, CopyItemActivity, etc.), first you need to add ApplyActivation activity to the workflow. With ApplyActivation activity we want to initialize the WorkflowContext object and then bind it to __Context property of CreateItemActivity.

    Let’s start by creating a new SharePoint 2010 Sequential Workflow project. In the wizard, choose List workflow and Announcements list. Once project is created, drag and drop ApplyActivation activity and CreateItemActivity to the designer.

    Select ApplyActivation activity and bind the __Context property to a new field (or property). To open the binding dialog, click (…) next to __Context property in the properties window. In the binding dialog, click on Bind to a new member tab and click OK to create the binding (see figure below).

    Repeat the same steps for __WorkflowProperties property, but instead of creating a new field/property, bind it to workflowProperties variable in the Bind to an existing member tab. For correct property bindings, refer to the figure below.

    Now that we have the workflow context, we can move to CreateItemActivity. Bind the __Context property to workflowContext variable created before. Next, bind the ListId property to ListId property of workflowContext.

    Next, we want to specify properties for the new item. In order to create new items, we need to pass in the ItemProperties to the activity in a form of a Hashtable. This Hashtable contains list field names and their desired values. Follow the steps below to add a hashtable and set the values:

    1. Right click on the CreateItemActivity property in the designer.
    2. Select Bind Property 'ItemProperties'.
    3. Create a new member for this property (e.g. itemProperties).
    4. Click OK to close the dialog.
    5. Double click onWorkflowActivated1 activity (we are going to use this activity to setup the item properties).
    6. Once in code view add the following code:
    itemProperties = new Hashtable (); 
    itemProperties.Add("Title", "My New Item Title"); 

    Check the two figures below for property bindings on CreateItemActivity and finished workflow in the designer.

    You can press F5 at this point and verify new item is created once you start the workflow. Other *ItemActivity activities work the same way - use ApplyActivation for workflow context, set the properties on *ItemActivity and you are all set.

    Peter Jausovec

  • Visual Studio SharePoint Development Blog

    How to get more information about the exceptions that can happen in SharePoint 2010 projects?


    In case there is an exception anywhere in the SharePoint 2010 project (most common place an exception would happen is during deployment of your SharePoint project, custom deployment configuration or custom deployment steps),  there’s a registry key EnableDiagnostics available for you to use. This DWORD registry key enables exception stack trace and type name logging which will be displayed in the Output window when exception occurs. Apart from using this to troubleshoot deployment, it can also be a tremendous help when you’re troubleshooting extensions. In order to use this functionality you need to restart Visual Studio 2010 once you set the registry key.

    Here’s the registry entry to enable diagnostics:

    Windows Registry Editor Version 5.00 

    Peter Jausovec

Page 1 of 1 (2 items)