Created
December 12, 2017 10:27
-
-
Save jcallaghan/58e68e127d15f7f2528802bce6b13fca to your computer and use it in GitHub Desktop.
Override created by or modified by property in SharePoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (SPSite site = new SPSite(SPContext.Current.Web.Url)) | |
{ | |
using (SPWeb web = site.OpenWeb()) | |
{ | |
web.AllowUnsafeUpdates = true; | |
SPList list = web.Lists["Shared Documents"]; | |
SPListItemCollection items = list.Items; | |
SPListItemCollection oListCollection = list.Items; | |
foreach (SPListItem oListItem in oListCollection) | |
{ | |
SPUser user = web.EnsureUser("New Account"); | |
SPFieldUserValue oUser = new SPFieldUserValue(web, user.ID, user.LoginName); | |
oListItem["Author"] = oUser; | |
oListItem["Editor"] = oUser; | |
oListItem.Update(); | |
} | |
web.AllowUnsafeUpdates = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment