我正在尝试检索完成任务的persdon的名称。在我的任务列表中,我可以看到编辑的“修改者” 在Sharepoint Manager中,我可以在Editor列中看到人员姓名。
如何在代码中获取此值
我创建了一个任务,在ontaskchanged
后我有一个代码块。我尝试了很多排列,但无法检索这些数据。
答案 0 :(得分:0)
private void UpdateCreatedByAndModifiedByFieldData(string strSiteUrl, string strListName, string strUserFieldName)
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(strSiteUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists[strListName];
foreach (SPListItem listItem in list.Items)
{
//Read user id from a list column of user type and create SPUser object
SPUser user = web.EnsureUser(listItem[strUserFieldName].ToString().Trim());
if (user != null)
{
string userValue = user.ID + ";#" + user.Name;
//Assign the above user to the "Created By" column
listItem["Author"] = userValue;
//Assign the above user to the "Modified By" column
listItem["Editor"] = userValue;
//Call the update method to apply the above changes
listItem.Update();
web.Update();
}
}
}
}
});
}
catch (Exception ex)
{
throw ex;
}
}
同时检查
How to get SharePoint file creator name using AllDocs table?