Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sharepoint SPWorkflowTask.AlterTask抛出;不支持指定的方法";_Sharepoint_Sharepoint 2010_Sharepoint Workflow - Fatal编程技术网

Sharepoint SPWorkflowTask.AlterTask抛出;不支持指定的方法";

Sharepoint SPWorkflowTask.AlterTask抛出;不支持指定的方法";,sharepoint,sharepoint-2010,sharepoint-workflow,Sharepoint,Sharepoint 2010,Sharepoint Workflow,我试图在新创建的Sharepoint任务上调用AlterTask,以将扩展属性添加到我的任务中,并引发NotSupportedException 发生了什么事?新创建的任务实际上是一个SharePoint列表项。ExtendedProperties是一个工作流任务属性 根据MSDN文件: The content type of the item passed to the task parameter is not derived from the WorkflowTask content ty

我试图在新创建的Sharepoint任务上调用AlterTask,以将扩展属性添加到我的任务中,并引发NotSupportedException


发生了什么事?

新创建的任务实际上是一个SharePoint列表项。ExtendedProperties是一个工作流任务属性

根据MSDN文件:

The content type of the item passed to the task parameter is not derived from the WorkflowTask content type.
这意味着表示新任务的SPListItem的内容类型必须设置为“Workflow Task”,然后才能对其调用AlterTask方法:

    Dim selectedTaskList As SPList = web.Lists(taskListName)

    ' Create a new task item
    Dim newTask As SPListItem = selectedTaskList.Items.Add()

   ' Turn the new task item into a Workflow Task
    Dim newTaskContentType As Microsoft.SharePoint.SPContentType = web.AvailableContentTypes("Workflow Task")
    newTask("ContentTypeId") = newTaskContentType.Id

   ' Now the AlterTask method will work.  (assume you've alreade declared a hashtable of properties to set)
    Microsoft.SharePoint.Workflow.SPWorkflowTask.AlterTask(newTask, myHashTable, True)
Protected Sub Page_Load(ByVal sender作为对象,ByVal e作为System.EventArgs)处理Me.Load
Dim IntItemID为整数
Dim siteId作为Guid=SPContext.Current.Site.ID
Dim webId作为Guid=SPContext.Current.Web.ID
将objSpSite用作新SPSite(siteId)
使用objSpWeb作为SPWeb=objSpSite.OpenWeb(webId)
如果不是Page.Request.QueryString(“ItemID”)为Nothing,则Page.Request.QueryString(“ItemID”)为Nothing
IntItemID=CInt(Page.Request.QueryString.Item(“ItemID”).ToString)
面板1.可见=错误
txtID.Text=IntItemID.ToString
Dim objList As SPList=objSpWeb.Lists(“请求列表”)
Dim objListItem作为SPListItem=objList.Items.GetItemById(IntItemID)
dtPermission.SelectedDate=objListItem(“许可日期”)
dtTimeFrom.SelectedDate=objListItem(“PermissionFromTime”)
dtTimeTo.SelectedDate=objListItem(“PermissionToTime”)
cmbType.SelectedValue=objListItem(“许可类型”)
'dtCreated.SelectedDate=objListItem(“”)
其他的
IntItemID=0
txtID.Text=“新建”
dtCreated.SelectedDate=今天
txtCreatedBy.Text=objSpWeb.CurrentUser.Name
将objServiceContext作为SPServiceContext=SPServiceContext.GetContext(objSpSite)进行调整
Dim objUserProfileManager作为新的UserProfileManager(objServiceContext)
Dim objUserProfile作为用户配置文件
Dim strUserAccount作为字符串
strUserAccount=objSpWeb.CurrentUser.LoginName.Replace(“i:0#.w |)”,“”)
如果objUserProfileManager.UserExists(strUserAccount),则
objUserProfile=objUserProfileManager.GetUserProfile(strUserAccount)
尝试
txtManager.Text=objUserProfile.GetManager.AccountName
特例
txtManager.Text=ex.Message
结束尝试
如果结束
面板2.可见=错误
如果结束
终端使用
终端使用
端接头
受保护的子cmdSubmit\u Click(发件人作为对象,e作为事件参数)处理cmdSubmit。单击
Dim siteId作为Guid=SPContext.Current.Site.ID
Dim webId作为Guid=SPContext.Current.Web.ID
将objSpSite用作新SPSite(siteId)
使用objSpWeb作为SPWeb=objSpSite.OpenWeb(webId)
objSpWeb.AllowUnsafeUpdates=True
作为SPList=objSpWeb.Lists(“请求列表”)的Dim列表
作为SPListItem=list.Items.Add()的Dim项
项目(“许可日期”)=dtPermission.SelectedDate
项目(“PermissionFromTime”)=dtTimeFrom.SelectedDate
项目(“PermissionToTime”)=dtTimeTo.SelectedDate
项目(“许可类型”)=cmbType.SelectedValue
项目(“PermissionApprover1”)=txtManager.Text
项目.更新()
list.Update()
objSpWeb.AllowUnsafeUpdates=False
终端使用
终端使用
端接头
受保护的子cmdApprove\u单击(发件人作为对象,e作为事件参数)处理cmdApprove。单击
Dim siteId作为Guid=SPContext.Current.Site.ID
Dim webId作为Guid=SPContext.Current.Web.ID
将objSpSite用作新SPSite(siteId)
使用objSpWeb作为SPWeb=objSpSite.OpenWeb(webId)
Dim objList As SPList=objSpWeb.Lists(“请求列表”)
Dim objListItem作为SPListItem=objList.Items.GetItemById(CInt(txtID.Text))
作为SPWorkflowTask的Dim objWFTask=objListItem.Tasks(0)
如果objWFTask什么都不是,那么
“没有匹配的任务
返回
如果结束
"改变任务"
Dim ht作为新哈希表()
ht(“状态”)=“完成”
ht(“完成百分比”)=1.0F
SPWorkflowTask.AlterTask(TryCast(objWFTask,splistem),ht,True)
终端使用
终端使用
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim IntItemID As Integer
    Dim siteId As Guid = SPContext.Current.Site.ID
    Dim webId As Guid = SPContext.Current.Web.ID
    Using objSpSite As New SPSite(siteId)
        Using objSpWeb As SPWeb = objSpSite.OpenWeb(webId)

            If Not Page.Request.QueryString("ItemID") Is Nothing And Page.Request.QueryString("ItemID") <> "" Then
                IntItemID = CInt(Page.Request.QueryString.Item("ItemID").ToString)
                Panel1.Visible = False

                txtID.Text = IntItemID.ToString
                Dim objList As SPList = objSpWeb.Lists("RequestList")
                Dim objListItem As SPListItem = objList.Items.GetItemById(IntItemID)
                dtPermission.SelectedDate = objListItem("PermissionDate")
                dtTimeFrom.SelectedDate = objListItem("PermissionFromTime")
                dtTimeTo.SelectedDate = objListItem("PermissionToTime")
                cmbType.SelectedValue = objListItem("PermissionType")
                'dtCreated.SelectedDate = objListItem("")

            Else
                IntItemID = 0
                txtID.Text = "New"
                dtCreated.SelectedDate = Today
                txtCreatedBy.Text = objSpWeb.CurrentUser.Name
                Dim objServiceContext As SPServiceContext = SPServiceContext.GetContext(objSpSite)
                Dim objUserProfileManager As New UserProfileManager(objServiceContext)

                Dim objUserProfile As UserProfile
                Dim strUserAccount As String
                strUserAccount = objSpWeb.CurrentUser.LoginName.Replace("i:0#.w|", "")
                If objUserProfileManager.UserExists(strUserAccount) Then
                    objUserProfile = objUserProfileManager.GetUserProfile(strUserAccount)
                    Try
                        txtManager.Text = objUserProfile.GetManager.AccountName
                    Catch ex As Exception
                        txtManager.Text = ex.Message
                    End Try

                End If


                Panel2.Visible = False

            End If

        End Using
    End Using


End Sub

Protected Sub cmdSubmit_Click(sender As Object, e As EventArgs) Handles cmdSubmit.Click
    Dim siteId As Guid = SPContext.Current.Site.ID
    Dim webId As Guid = SPContext.Current.Web.ID

    Using objSpSite As New SPSite(siteId)
        Using objSpWeb As SPWeb = objSpSite.OpenWeb(webId)
            objSpWeb.AllowUnsafeUpdates = True
            Dim list As SPList = objSpWeb.Lists("RequestList")
            Dim item As SPListItem = list.Items.Add()
            item("PermissionDate") = dtPermission.SelectedDate
            item("PermissionFromTime") = dtTimeFrom.SelectedDate
            item("PermissionToTime") = dtTimeTo.SelectedDate
            item("PermissionType") = cmbType.SelectedValue
            item("PermissionApprover1") = txtManager.Text

            item.Update()
            list.Update()
            objSpWeb.AllowUnsafeUpdates = False
        End Using
    End Using

End Sub

Protected Sub cmdApprove_Click(sender As Object, e As EventArgs) Handles cmdApprove.Click
    Dim siteId As Guid = SPContext.Current.Site.ID
    Dim webId As Guid = SPContext.Current.Web.ID
    Using objSpSite As New SPSite(siteId)
        Using objSpWeb As SPWeb = objSpSite.OpenWeb(webId)
            Dim objList As SPList = objSpWeb.Lists("RequestList")
            Dim objListItem As SPListItem = objList.Items.GetItemById(CInt(txtID.Text))

            Dim objWFTask As SPWorkflowTask = objListItem.Tasks(0)

            If objWFTask Is Nothing Then
                ' no matching task
                Return
            End If

            ' alter the task
            Dim ht As New Hashtable()

            ht("Status") = "Complete"
            ht("PercentComplete") = 1.0F

            SPWorkflowTask.AlterTask(TryCast(objWFTask, SPListItem), ht, True)
        End Using
    End Using