Partager via


CreateTaskWithContentType Class

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

Inheritance Hierarchy

System.Object
  System.Workflow.ComponentModel.DependencyObject
    System.Workflow.ComponentModel.Activity
      System.Workflow.Activities.CallExternalMethodActivity
        Microsoft.SharePoint.WorkflowActions.CreateTaskWithContentType

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

Syntax

<ActivityToolboxDisplayAttribute("VSTTSharePointWorkflowTask", True)> _
<ToolboxBitmapAttribute(GetType(CreateTaskWithContentType), "Resources.CreateTaskWithContentType.bmp")> _
Public NotInheritable Class CreateTaskWithContentType _
    Inherits CallExternalMethodActivity

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

Remarks

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.

Examples

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;
            }
        }

Thread Safety

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

See Also

Reference

CreateTaskWithContentType Members

Microsoft.SharePoint.WorkflowActions Namespace