I need to add new version of the file to SPFileCollection without changing version (it is a system update of the content of pdf file)
UpdateOverwriteVersion allows me to change metadata but is there a way to change content (bytes) of the file?
WORKAROUND:
Ok, as Stefan found out, there is no satisfactory solution to this.
I found two workarounds:
1.
(Be aware that turning off the version control could lead to wrong behavior, if there are people working on that list… – Stefan)
oFile = oWeb.GetFile(url);
oFile.Item.ListItems.List.EnableVersioning = false;
oFile.Item.ListItems.List.Update();
oFolder.Files.Add(oFile.Name, aBytes, fileProperties, true);
oFile.Item.ListItems.List.EnableVersioning = true;
oFile.Item.ListItems.List.Update();
2.
oFile = oWeb.GetFile(sAdres);
int iFileVersion = oFile.UIVersion;
oFolder.Files.Add(oFile.Name, aBytes, fileProperties, true);
oFileVersion = oFile.Versions.GetVersionFromID(iFileVersion);
if (null != oFileVersion && !oFileVersion.IsCurrentVersion)
{
oFileVersion.Delete();
}
You can load theSPFileobject and then callSPFile.SaveBinary(Stream, SPFileSaveBinaryParameters)method to update it’s content.With the
CreateVersionproperty of theSFileSaveBinaryParametersyou can specify whether a new version should be created or not.A quote from a moderator at Microsoft TechNet forum.