Sharepoint Deleting an Item from a list using UpdateListItems WebService

Jack picture Jack · Sep 3, 2009 · Viewed 9.8k times · Source

I am trying to delete an item from a list and have the following xml

<Batch PreCalc='TRUE' OnError='Continue'>
    <Method ID='1' Cmd='Delete'>\
        <Field Name='ID'>185</Field>       
    </Method>
</Batch>

This is returning the following error

0x81020030 - Invalid file name

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

It looks like I need to provide the fileName rather than just using the ID. My attempts to do this have failed so far.

Update

I think the XML needs to be in the following format:

<Batch PreCalc='TRUE' OnError='Continue'>
    <Method ID='1' Cmd='Delete'>
        <Field Name='ID'>185</Field>
        <Field Name="FileRef">http://sharepoint.mycompany.com/testsite/lib/flying spider  2009-09-03  P.jpg</Field>       
    </Method>
</Batch>

No error is thrown but nothing is being deleted.

Update 2

After Alex reply I removed the spaces in the url and have removed and tabs/ newlines as this "may" cause a problem:

<Batch PreCalc='TRUE' OnError='Continue'>
  <Method ID='1' Cmd='Delete'>
    <Field Name='ID'>185</Field>
    <Field Name="FileRef">http://sharepoint.mycompany.com/testsite/lib/flying%20spider%202009-09-03  P.jpg</Field>
  </Method>
</Batch>

Again no error is thrown.

Should I be using FileRef? FileLeafRef? Should I me using the file name? relative path? URL to file?

If this matters this is a Picture Libary

Answer

Alex Angas picture Alex Angas · Sep 3, 2009

This is probably because there are spaces in the filename and SharePoint can't find the item. Have you tried replacing each space with %20?

According to the MSDN How to: Update List Items article:

Posting the UpdateListItems method silently fails if a specified item does not exist.

If this doesn't work you could try specifying the ListVersion and ViewName attributes on the Batch element. Every example I've seen specifies these.