Sharepoint Removing an item from a list using UpdateListItems WebService

I am trying to remove 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 returns 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 a filename and not just use an id. My attempts to do this have so far failed.

Update

I think the XML should 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>

      

The error is not thrown, but nothing is removed.

Update 2

Following Alex's answer, I removed the spaces in the url and removed the tabs / newlines as well, as this might "cause" the 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>

      

No error occurs again.

Should I be using FileRef? FileLeafRef? Should I use the filename? relative path? File url?

If it matters it's Picture Libary

+2


source to share


3 answers


This is likely because there are spaces in the file name and SharePoint cannot find the item. Have you tried replacing every space with %20

?

According to MSDN How to update list items :



The UpdateListItems method posting silently fails if the specified item does not exist.

If this does not work, you can try to specify the attributes ListVersion

and ViewName

the element Batch

. Every example I've seen indicates them.

+1


source


Try also,



Remove item from SharePoint list, etc.

+1


source


I recently faced the same problem, you need to provide the relative path to the item to be removed as well as the ID as shown below:

<Batch OnError="Return">
  <Method ID="1">
    <Field Name="ID">123456</Field>
    <Field Name="FileRef">sites/library/folderNameOrFileName</Field>
  </Method>
</Batch>

      

0


source







All Articles