다음을 통해 공유


CreateTaskWithContentType Class

Defines a workflow activity that is used to create a task item in a Microsoft SharePoint Foundation 2010 task list, using a specified SharePoint Foundation 2010 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

'Declaration
<ToolboxBitmapAttribute(GetType(CreateTaskWithContentType), "Resources.CreateTaskWithContentType.bmp")> _
<ActivityToolboxDisplayAttribute("VSTTSharePointWorkflowTask", True)> _
Public NotInheritable Class CreateTaskWithContentType _
    Inherits CallExternalMethodActivity
'Usage
Dim instance As CreateTaskWithContentType
[ToolboxBitmapAttribute(typeof(CreateTaskWithContentType), "Resources.CreateTaskWithContentType.bmp")]
[ActivityToolboxDisplayAttribute("VSTTSharePointWorkflowTask", true)]
public sealed class CreateTaskWithContentType : CallExternalMethodActivity

Remarks

You must ensure that content types are enabled on the SharePoint Foundation 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

MVP Icon

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

Get to know your SharePoint Foundation 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;
            }
        }
Public Shared Sub VerifyModifyTaskList(ByVal taskList As SPList, ByVal contentType As String)
   Try
      Dim contentTypeId As New SPContentTypeId(contentType)
   taskList.ContentTypesEnabled = True
                Dim matchContentTypeId As SPContentTypeId = taskList.ContentTypes.BestMatch(contentTypeId)
                If matchContentTypeId.Parent.CompareTo(contentTypeId) <> 0 Then
                    Dim ct As SPContentType = taskList.ParentWeb.AvailableContentTypes(contentTypeId)
                    taskList.ContentTypes.Add(ct)
                    taskList.Update()
                End If
            Catch
                Throw
            End Try
End Sub

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