开发者

update created by and modified by filed in document library, sharepoint 2010

开发者 https://www.devze.com 2023-02-17 07:49 出处:网络
i have uploaded the document in document library using event handler in sharepoint 2010. but when the document is uploaded the created by and modified field is always show system account user.if my lo

i have uploaded the document in document library using event handler in sharepoint 2010. but when the document is uploaded the created by and modified field is always show system account user.if my login user is other then system account to开发者_开发百科o. so, can any one help me how to update document library modified by and created by field using event handler. my code to update field is:

item.Web.AllowUnsafeUpdates = true; item["Author"] = "testuser"; item.Update(); item.Web.AllowUnsafeUpdates = false;

but i got the error: Author field is read only.

please help me.


When file is an SPFile object and oUser is an SPUser object, you can set the Created/Modified values with this approach:

file.Item["Created"] = DateTime.Now.AddDays(-30);
file.Item["Modified"] = DateTime.Now.AddDays(-30);

file.Item["Created By"] = oUser;
file.Item["Modified By"] = oUser;

file.Item.Update();

With this the names of created/modified by get updated with the name of oUser, and the modified/created dates get updated with the date of last month (30 days back).

Don't forget to update the item afterwards to save the changes.


some code i have for importing documents

$user = $web.EnsureUser(@"domain\user")
$item["Created By"] = $user
$item["Modified By"] = $user
$item.UpdateOverwriteVersion();
0

精彩评论

暂无评论...
验证码 换一张
取 消