In last article we saw how to create a new folder in document library using SharePoint REST Services. Now we will see how to delete the folder using SharePoint REST services.
Following is the SharePoint REST service URL:
/_api/web/GetFileByServerRelativeUrl('/[LIBRARY_NAME]/[FOLDER_NAME]')
Parameter: server relative URL of folder.
HTTP Method: POST
and remember header should contain following lines:
"X-RequestDigest": digest,
"IF-MATCH": "*",
"X-HTTP-Method" :"DELETE"
Following is the sample code:
<html>
<head>
<script src="/Site%20Assets/js/jquery-1.11.1.min.js"></script>
<script>
function DeleteFolder()
{
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('/testdoc/test1')",
method: "POST",
headers: {
"ACCEPT": "application/json;odata=verbose",
"X-RequestDigest": digest,
"IF-MATCH": "*",
"X-HTTP-Method" :"DELETE"
},
success: function (data) {
alert("Delete successfully");
},
error: function (data) {
alert("Error occured." + data.responseText);
}
});
});
}
</script>
</head>
<body>
<div>
<input type="submit" onclick="DeleteFolder()" value="Delete Folder"> </input>
</div>
</body>
</html>
Following is the SharePoint REST service URL:
/_api/web/GetFileByServerRelativeUrl('/[LIBRARY_NAME]/[FOLDER_NAME]')
Parameter: server relative URL of folder.
HTTP Method: POST
and remember header should contain following lines:
"X-RequestDigest": digest,
"IF-MATCH": "*",
"X-HTTP-Method" :"DELETE"
Following is the sample code:
<html>
<head>
<script src="/Site%20Assets/js/jquery-1.11.1.min.js"></script>
<script>
function DeleteFolder()
{
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('/testdoc/test1')",
method: "POST",
headers: {
"ACCEPT": "application/json;odata=verbose",
"X-RequestDigest": digest,
"IF-MATCH": "*",
"X-HTTP-Method" :"DELETE"
},
success: function (data) {
alert("Delete successfully");
},
error: function (data) {
alert("Error occured." + data.responseText);
}
});
});
}
</script>
</head>
<body>
<div>
<input type="submit" onclick="DeleteFolder()" value="Delete Folder"> </input>
</div>
</body>
</html>
No comments:
Post a Comment