I have a library with versioned files. I have versioned files prepared for uploading (1 version = 1 file). How do I create new version? Do I just set file's Content property and Update it? Please share your experinces, thanks

edit: I have something like this:


So I have missing versions. Is it possible to set file version when uploading (item's field?)? If not, I will fill missing version with previous/next versions, for example File2|v1 will be filled with File2|v2.

  • Can you clarify what you mean by "prepared for uploading"? Do you mean you have documents outside of SharePoint that have multiple versions? Do the different versions of a file have the same name?
    – Laurie
    May 6, 2011 at 18:40
  • Yes, I have files outside of Sharepoint. I'll upload them programatically, so I can give them any name. Files are stored in a DB and I know which file is which version.
    – redman
    May 6, 2011 at 21:25
  • So, you want to keep the original version numbers and not have SharePoint assign the version numbers in order, right?
    – Laurie
    May 6, 2011 at 22:53
  • If possible yes, but otherwise I will fill gaps with other versions...
    – redman
    May 6, 2011 at 23:23

3 Answers 3


I don't know how to programmatically assign the version number, but if it is OK to let SharePoint assign the version number...

With the server version of the method:

SPFileCollection.Add(urlOfFile, fileContent, overwrite);

if you pass in overwrite=true and the document library has versioning turned on, I think it will create a new version of the document. (That's the behavior through the browser.) I assume the Client Object Model version of the method would behave the same way.

FileCreationInformation fci = new FileCreationInformation();
fci.Url = urlOfFile;
fci.Content = fileContent;
fci.Overwrite = true;

So, as long as you upload the files in the correct order of their versions, SharePoint should create each version for you.

  • 1
    But will it create a minor or major number of version?
    – redman
    May 7, 2011 at 11:22
  • I haven't tested it, but it should adhere to however you set it up on your document library under Library Settings > Versioning settings.
    – Laurie
    May 7, 2011 at 16:14

Here is a little code sample that will simulate versioning of a file

public File changeDocumentVersion(string version,File file){
    string [] versions = version.Split(new char[]{'.'});
    int minor = Int32.Parse(versions[1]);
    int major = Int32.Parse(versions[0]);

    for (int i = 1; i < major; i++)
        file.CheckIn("versioning", CheckinType.MajorCheckIn);
    for (int i = 0; i < minor; i++)
        file.CheckIn("versioning", CheckinType.MinorCheckIn);
    return file;

As long as you have enabled versioning (found under list/library settings, then versioning) enabled SP will take care of the versioning for you.

  • This means that if I get a document with Client Object Model, change it's Content property and do Update on this document, it will automatically create new version?
    – redman
    May 6, 2011 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.