This documentation is archived and is not being maintained.

CreateTaskWithContentType Class

Windows SharePoint Services 3

Creates a task item in a Windows SharePoint Services 3.0 task list, using a specified Windows SharePoint Services 3.0 content type.

Namespace:  Microsoft.SharePoint.WorkflowActions
Assembly:  Microsoft.SharePoint.WorkflowActions (in Microsoft.SharePoint.WorkflowActions.dll)

[ActivityToolboxDisplayAttribute("VSTTSharePointWorkflowTask", true)]
[ToolboxBitmapAttribute(typeof(CreateTaskWithContentType), "Resources.CreateTaskWithContentType.bmp")]
public sealed class CreateTaskWithContentType : CallExternalMethodActivity

You must ensure that content types are enabled on the Windows SharePoint Services 3.0 task list where you are creating the task list items. If they are not enabled on this list, the activity will throw a a null reference (Nothing in Visual Basic) reference exception.

The following code sample was contributed by Robert Bogue, one of the Windows SharePoint Services 3.0 MVPs.

Get to know your Windows SharePoint Services 3.0 MVPs on this Web site.

The following code sample updates a content type.

public static void VerifyModifyTaskList(SPList taskList, string contentType)
{
   try
   {
      SPContentTypeId contentTypeId = new  
      SPContentTypeId(contentType);
   taskList.ContentTypesEnabled = true;
                SPContentTypeId matchContentTypeId = taskList.ContentTypes.BestMatch(contentTypeId);
                if (matchContentTypeId.Parent.CompareTo(contentTypeId) != 0)
                {
                    SPContentType ct = taskList.ParentWeb.AvailableContentTypes[contentTypeId];
                    taskList.ContentTypes.Add(ct);
                    taskList.Update();
                }
            }
            catch
            {
                throw;
            }
        }

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show: