Till now we see how to work with folders and files using SharePoint 2013 REST services, now in this article we will see how to check out the file using SharePoint 2013 REST services. Check out is an important operation in SharePoint. It helps you to get hold on the file so that others cannot work on it at the time you are working.
Following is the REST service to check out the file:
"/_api/web/GetFileByServerRelativeUrl('[File server relative url]')/CheckOut()
"/_api/web/GetFileByServerRelativeUrl('[File server relative url]')/CheckOut()
Following is the complete code to check out the file:
<html>
<head>
<script src="/Site%20Assets/js/jquery-1.11.1.min.js"></script>
<script>
function CheckOutFile()
{
var digest = "";
$.ajax(
{
url: "/_api/contextinfo",
method: "POST",
headers: {
"ACCEPT": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose"
},
success: function (data) {
digest = data.d.GetContextWebInformation.FormDigestValue;
},
error: function (data) {
}
}).done(function() {
$.ajax(
{
url: "/_api/web/GetFileByServerRelativeUrl('/doc/folder1/test1.doc')/CheckOut()",
method: "POST",
headers: {
"ACCEPT": "application/json;odata=verbose",
"X-RequestDigest": digest
},
success: function (data) {
alert("Checked out");
},
error: function (data) {
alert("Error occured." + data.responseText);
}
});
});
}
</script>
</head>
<body>
<div>
<input type="submit" onclick="CheckOutFile()" value="Check out File"> </input>
</div>
</body>
</html>
<html>
<head>
<script src="/Site%20Assets/js/jquery-1.11.1.min.js"></script>
<script>
function CheckOutFile()
{
var digest = "";
$.ajax(
{
url: "/_api/contextinfo",
method: "POST",
headers: {
"ACCEPT": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose"
},
success: function (data) {
digest = data.d.GetContextWebInformation.FormDigestValue;
},
error: function (data) {
}
}).done(function() {
$.ajax(
{
url: "/_api/web/GetFileByServerRelativeUrl('/doc/folder1/test1.doc')/CheckOut()",
method: "POST",
headers: {
"ACCEPT": "application/json;odata=verbose",
"X-RequestDigest": digest
},
success: function (data) {
alert("Checked out");
},
error: function (data) {
alert("Error occured." + data.responseText);
}
});
});
}
</script>
</head>
<body>
<div>
<input type="submit" onclick="CheckOutFile()" value="Check out File"> </input>
</div>
</body>
</html>
No comments:
Post a Comment