Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.