0

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?

1 Answer 1

0

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.

1
  • 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
    Commented Apr 3, 2012 at 6:16

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.