Using an ithit-webdav server implementation in combination with an ASP.NET MVC4 application I represent several Excel documents to the user that can be opened and saved to the webdav server including versioning. Editing is done by a JavaScript function that will handle a click on the file's URL that is on the page. For IE the handler uses the Sharepoint plugin and otherwise the winFirefoxPlugin. This all works fine. The user can check-out a file, edit and save the file, check-in the file and the version number is increased.
But now the user should be able to show a previous version of the file. I can show a list of all existing versions of a file but I don't know how I can generate link that the user can click for opening the file using the javascript handler. The only thing I can think of is creating a temporary file containing the specific version on the webdav server and open the temporary file (when to delete?).
Does someone know a better solution?
var editDocument = function () {
var $a = $(this),
doc = $a.attr("href");
var plugin = navigator.plugins["SharePoint.OpenDocuments"];
if (!plugin) {
try {
plugin = new ActiveXObject('SharePoint.OpenDocuments');
} catch (err) {
//window.alert("Unable to create ActiveX object");
//return false;
}
}
if (plugin) {
plugin.EditDocument(doc);
} else {
try {
var ffPlugin = document.getElementById("winFirefoxPlugin");
ffPlugin.EditDocument(doc);
} catch (e) {
alert("Editing not supported. (" + e.message + ")");
}
}
return false;
};
The versions URLs totally depend on the server implementation. The code generated by WebDAV wizards for Visual Studio forms version urls like this:
To get file versions list for particular file on the client side in JavaScript you can use the IT Hit WebDAV Ajax Library. The File.GetVersionsAsync() method returns an array of Version objects. Each Version object has a Href property wich is a version URL:
In case you wish to get the versions list request yourself here is an example of request and response:
IMPORTANT! The code generated by WebDAV wizards for Visual Studio generate version URLs with parameters. Microsoft Office truncates parameters when opening documents. That's why you must change your server implementation to generate version urs without parameters if you want to save versions back to server. The version URL must look for example like this:
The code that generates the version URL is located in Version.cs file:
The code that parses the version url and returns Version object to the engine is in DavContext.cs file: