SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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 '11 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. – Andrej Cimperšek May 6 '11 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 '11 at 22:53
If possible yes, but otherwise I will fill gaps with other versions... – Andrej Cimperšek May 6 '11 at 23:23
up vote 1 down vote accepted

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.

share|improve this answer
But will it create a minor or major number of version? – Andrej Cimperšek May 7 '11 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 '11 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;
share|improve this answer
thanks for fix :) – Sebastien Stettler Oct 4 '11 at 23:03

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

share|improve this answer
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? – Andrej Cimperšek May 6 '11 at 21:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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