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?
Add a comment
|
1 Answer
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:
- Through the SharePoint object mode SPFileVersion.OpenBinary/OpenBinaryStream
- 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.
-
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– matt137Commented Apr 3, 2012 at 6:16