I want to make rest call or implement some JSOM mechanism to retrieve previous version file from _vti_history
.
For example: _vti_history/1024/Documents/Filename.docx
Please guide me if this is possible in some way.
Thanks,
Kailash
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityYou can use below to get file versions history, there is rest endpoint available which will give you all version of a file using item id, also it can be done using JSOM.
REST API
/sites/yoursite/_api/Web/Lists(@v0)/Items(@v1)/Versions?&@v0=guid'112313-13cebe-1233-822e-asd123123123'&@v1=10
JSOM (ref link)
var oItems, clientContext, oFile, oFileVersions;
function GetAllVersions() {
// You can optionally specify the Site URL here to get the context
// If you don't specify the URL, the method will get the context of the current site
// var clientContext = new SP.ClientContext("http://MyServer/sites/SiteCollection");
clientContext = new SP.ClientContext();
// Get List Object
var olistCollection = clientContext.get_web().get_lists();
var oList = olistCollection.getByTitle("Documents");
// Get Item using CAML Query
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'FileLeafRef\'/>' + '<Value Type=\'File\'>Document.docx</Value></Eq></Where></Query></View>');
oItems = oList.getItems(camlQuery);
// Load List Item collection object
clientContext.load(oItems);
// Execute the query to the server.
clientContext.executeQueryAsync(onsuccess, onfailed);
}
function onsuccess() {
// Loop through each Item.
var itemCount = oItems.get_count();
for (var i = 0; i <= itemCount - 1; i++) {
// Get File object of the list item
oFile = oItems.itemAt(i).get_file();
oFileVersions = oFile.get_versions();
clientContext.load(oFileVersions);
break;
}
//Execute the batch
clientContext.executeQueryAsync(FinalQuerySuccess, FinalQueryFailure);
}
function onfailed(sender, args) {
console.log('Failed' + args.get_message() + '\n' + args.get_stackTrace());
}
function FinalQuerySuccess(sender, args) {
// Iterate through Enumerator
var oEnumerator = oFileVersions.getEnumerator();
while (oEnumerator.moveNext()) {
var oFile = oEnumerator.get_current();
console.log("Version Label : " + oFile.get_versionLabel());
console.log("Version Comment : " + oFile.get_checkInComment());
}
}
function FinalQueryFailure(sender, args) {
console.log('Failed' + args.get_message() + '\n' + args.get_stackTrace());
}