Skip to content

Instantly share code, notes, and snippets.

@jcallaghan
Created December 12, 2017 10:27
Show Gist options
  • Save jcallaghan/58e68e127d15f7f2528802bce6b13fca to your computer and use it in GitHub Desktop.
Save jcallaghan/58e68e127d15f7f2528802bce6b13fca to your computer and use it in GitHub Desktop.
Override created by or modified by property in SharePoint
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