Wednesday, August 22, 2012

Update Modified / Created in List Item

I would like to migrate a site to another SharePoint Server as a site collection. Unfortunately, I cannot export the site using "Save site as template" (many issues needed to be solved, such as MaxTemplateDocumentSize). 

Apart from "Save site as template", I can choose between site collection backup and export site. For site collection, it includes fields Modified By, Created By, Created and Modified which are absent in site (*.cmp) file. In fact, I cannot move a site up one level without importing site file(*.cmp). Here is a method to update those fields programatically:

            SPListItem item = workflowProperties.Item;
            SPUser user = workflowProperties.Web.AllUsers[@"Test\wawa"];
            SPFieldUserValue currentUser = new SPFieldUserValue(workflowProperties.Web, user.ID, user.LoginName);
            item["Author"] = currentUser;
            item["Editor"] = currentUser;
            item.UpdateOverwriteVersion();

No comments:

Post a Comment