The process of building custom solutions for SharePoint Server.
The SystemUpdate method has a bool param which you can set to false that will not affect the modified by.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am using following code to upload a file in library and setting column values. This library has Major versioning enabled. Problem I am facing is on each file upload, it creates two versions, first version is for file upload and second version is for updating column values. Can we do it in one go i.e. upload and setting column values only create one version?
I tried spfile.ListItemAllFields.SystemUpdate(); instead of spfile.ListItemAllFields.Update(); but then it didn't update the Editor field and saved it as System Account
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteURL))
{
using (SPWeb web = site.OpenWeb(mySubSite))
{
Byte[] bytes = Convert.FromBase64String(Attachment);
SPFolder myLibrary = web.Folders[myLibrary];
web.AllowUnsafeUpdates = true;
SPFile spfile = myLibrary.Files.Add(FileName, bytes, true);
spfile.ListItemAllFields["Editor"] = web.EnsureUser(UploadedBy).ID;
spfile.ListItemAllFields["Product"] = Product;
spfile.ListItemAllFields.Update();
web.AllowUnsafeUpdates = false;
myLibrary.Update();
}
}
});
The process of building custom solutions for SharePoint Server.
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more
The SystemUpdate method has a bool param which you can set to false that will not affect the modified by.