Workflow Impersonation
-
hi, i want to perform a task in a specific workflow in my sharepoint Site using a job. the problem by using code below,that impersonation doesn't work when i go to list of tasks and check who perform the task i find that user is always System\Account. could you tell me what's wrong with that code ? the line who made impersonation are in bold var q = new SPSiteDataQuery(); q.Lists = ""; q.Query = "0x0108011"; q.Webs = ""; q.ViewFields = ""; q.ViewFields += ""; q.ViewFields += ""; q.ViewFields += ""; q.RowLimit = 10; SPSite site = new SPSite("http://abt-mossdev/"); SPWeb web = site.OpenWeb(); SPUser user = web.AllUsers(YesMan); SPUserToken token = user.UserToken; SPSite impersonatedSiteCollection = new SPSite(SiteUrl, token); DataTable dt = impersonatedSiteCollection.RootWeb.GetSiteData(q); foreach (DataRow row in dt.Rows) { string listId = row("ListId"); SPList taskList = web.Lists(new Guid(listId)); string taskId = row("ID"); var task = taskList.GetItemById(Convert.ToInt32(taskId)); //Performing the task Hashtable taskHash = new Hashtable(); taskHash("PercentComplete") = "1"; taskHash("IsApproved") = "1"; taskHash(SPBuiltInFieldId.Modified_x0020_By) = "yesman"; SPWorkflowTask.AlterTask(task, taskHash, true); Thank you all