Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top