Deleting a document through a sharepoint web service using jQuery

I am trying to delete a document using sharepoint webservice if someone uploads a document and then cancels it. I created the following function

    function DeleteDocument(libraryName, ID)
{
debug.log('DeleteDocument (Entry) libraryname = '+libraryName+' ID='+ID);
    var batch =
        "<Batch OnError='Continue'> \
            <Method ID='1' Cmd='Delete'> \
                <Field Name='ID'>" + ID + "</Field> \
            </Method> \
        </Batch>";

    var soapEnv =
        "<?xml version='1.0' encoding='utf-8'?> \
        <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' \
xmlns:xsd='http://www.w3.org/2001/XMLSchema' \
xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
          <soap:Body> \
            <UpdateListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
              <listName>"+libraryName+"</listName> \
              <updates> \
                " + batch + "</updates> \
            </UpdateListItems> \
          </soap:Body> \
        </soap:Envelope>";
    debug.log(soapEnv);
    $.ajax({
        url: "http://<serverandsite>/_vti_bin/lists.asmx",
        beforeSend: function(xhr) {
            xhr.setRequestHeader("SOAPAction",
            "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
        },
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: function(xData, status){          
            alert(xData.responseText);
            debug.log('xData response = ' + xData.responseText);
            debug.log('status response = ' + status);
        },
        contentType: "text/xml; charset=utf-8"
    });
}

When I run it, I get

0x81020030 - Invalid file name.

The specified file name cannot be used. This may be the name of an existing file or directory, or you may not have permission to access the file.

Does anyone have any idea why this might be unsuccessful. I am running code against a standard document library.

I tried it with checked and verified files and received the same message. I need this to work with verified documents, in fact they have never been verified, so I don’t know how I could solve fileref

+5
1

FileRef

<Field Name="FileRef">http://Server/[sites/][Site/]Library/File</Field>
+4

All Articles