none
Unable to delete a folder in info path library using rest api in SharePoint

    Question

  • Hi,

    I have used below script to delete folder in library along with files in folder but unable to delete folder. please help me

    var d = $.Deferred();
        $.ajax({
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetFolderByServerRelativeUrl('"+selectedreq+"')", 
            method: "POST",
            headers: {
    "ACCEPT": "application/json;odata=verbose",
    "IF-MATCH": "*",
       "X-HTTP-Method":"DELETE",
       "X-RequestDigest": $('#__REQUESTDIGEST').val()  
       },
            success: function(data) {
    d.resolve(data);        
            },
            error: function(data) {
    alert(JSON.stringify(data));
                d.reject();
            }
        }); 
        return d.promise();

                                                      
    Saturday, July 15, 2017 7:38 AM

All replies

  • Are you getting any error message while executing above REST code? Please share your error message, if your getting any error...To further troubleshoot this issue, make sure your providing proper ServerRelativeUrl of the folder in your REST API end point...
    Saturday, July 15, 2017 11:19 AM
  • Hi,

    Please check whether the folder url is right or not, the following code for your reference:

    <script src="//code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    function deleteFolder(){
    	var selectedreq=$("#folderUrl").val();
    	$.ajax({
    		url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetFolderByServerRelativeUrl('"+selectedreq+"')", 
    		method: "POST",
    		async: false,
    		headers: { 
    			"ACCEPT": "application/json;odata=verbose",
    			"IF-MATCH": "*",
    			"X-HTTP-Method":"DELETE",
    			"X-RequestDigest": $('#__REQUESTDIGEST').val()  
    		},
    		success: function(data) {
    			console.log(data);
    		},
    		error: function(data) {
    			console.log(JSON.stringify(data));
    		}
    	}); 
    }
    </script>
    FolderUrl:<input id="folderUrl" type="text"/> <input type="button" value="Delete" onclick="deleteFolder();"/>

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, July 18, 2017 7:52 AM
    Moderator
  • Thanks you. it working code.
    Monday, February 11, 2019 1:01 PM