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 document library with enabled versioning, I added an xml file, then added it again, but I have edited one value in it. Now I would like to get the content of both files in C# to compare them. I know this could be achieved with SPFileVersion.OpenBinary(), but I would prefer to get it with myFile = web.GetFile(SPFileVersion.Url) and then operate on myFile.OpenBinary. Unfortunately GetFile() doesn't seem to be working here, I tried different path combinations (with site url, without it) and most of the fields in myFile throw FileNotFoundException. Does someone know, if is is possible at all to get the content of previous versions of the file like that?

share|improve this question
up vote 0 down vote accepted

You can't get a SPFile from the SPFileVersion.Url, the Exists property will be false as it isn't the right url for the file.

There is two ways for you to get the content of the old version:

  1. Through the SharePoint object mode SPFileVersion.OpenBinary/OpenBinaryStream
  2. Through a web request for SPFileVersion.Url (prefixed by SPWeb.Url)

If your code runs on the server you should always use method 1. Method 2 is for when you want to allow client computers to download the file.

share|improve this answer
ok, thanks for clearing this up, I thought since with the second method you get a link to a physical file, it could also be used in GetFile() method – matt137 Apr 3 '12 at 6:16

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.