我正在以编程方式尝试将sharepoint 2013工作流任务从“DOMAIN \ Test1”用户委派给“DOMAIN \ Test2”用户。它委托“DOMAIN \ Test2”用户,但当我尝试使用委派用户(“DOMAIN \ Test2”)帐户访问任务项目URL时,我收到以下错误:
“您无权回复此项目。”
using (SPSite currentSite = new SPSite("http://tst:001/sites/Test"))
{
using (SPWeb currentWeb = currentSite.OpenWeb())
{
string tasksList = "Workflow Tasks";
SPUser delegateTouser = currentWeb.EnsureUser("DOMAIN\\Test2");
SPListItem listItem = currentWeb.Lists.TryGetList(tasksList).GetItemById(101);
listItem[SPBuiltInFieldId.AssignedTo] = delegateTouser;
listItem[SPBuiltInFieldId.WorkflowVersion] = "1";
listItem.Update();
}
}
答案 0 :(得分:0)
打开网站时使用RunWithElevatedPrivileges:
SPSecurity.RunWithElevatedPrivileges(delegate(){
using (SPSite currentSite = new SPSite("http://tst:001/sites/Test"))
{
using (SPWeb currentWeb = currentSite.OpenWeb())
{
string tasksList = "Workflow Tasks";
SPUser delegateTouser = currentWeb.EnsureUser("DOMAIN\\Test2");
SPListItem listItem = currentWeb.Lists.TryGetList(tasksList).GetItemById(101);
listItem[SPBuiltInFieldId.AssignedTo] = delegateTouser;
listItem[SPBuiltInFieldId.WorkflowVersion] = "1";
listItem.Update();
}
}
});