UpdateListItem web service not working for "Delete" but working for "Update" - InfoPath Dev
in

InfoPath Dev

UpdateListItem web service not working for "Delete" but working for "Update"

Last post 01-08-2016 12:52 PM by Hilary Stoupa. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 01-08-2016 03:26 AM

    UpdateListItem web service not working for "Delete" but working for "Update"

    Hi, I am trying to delete a form from SharePoint InfoPath Library by calling web service "UpdateListItem" method but the form isn't getting deleted, whereas on the same command I tried to Update and it is successful. Here is my code for calling web service method. StringBuilder sb = new StringBuilder(); sb.Append("Method ID='1' Cmd='Delete'"); sb.Append(String.Format("Field Name=\ID\" + id_value + "/Field")); sb.Append(String.Format("Field Name=\"FileRef\" + URL +"/Field")); sb.Append("/Method"); System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch"); elBatch.SetAttribute("OnError", "Continue"); elBatch.SetAttribute("PreCalc", "TRUE"); elBatch.SetAttribute("ListVersion", "1"); elBatch.SetAttribute("ViewName", "view_id without '{}' braces"); elBatch.InnerXml = sb.ToString(); XmlNode ndReturn = client.UpdateListItems(ListID, elBatch); Certain tags are not shown in command please get the actual code in attachment. Any help will be greatly appreciated. Thanks, SK.
    Suthar
  • 01-08-2016 07:40 AM In reply to

    Re: UpdateListItem web service not working for "Delete" but working for "Update"

    So, your code sample in the text file has the Cmd in the Method as Update - if you use the same code and change to Delete, it doesn't work? Can you run Fiddler while you try this in preview so you can see the response from the web service?
    Hilary Stoupa

  • 01-08-2016 08:02 AM In reply to

    Re: UpdateListItem web service not working for "Delete" but working for "Update"

     So, using U2U CAML Query Editor (my favorite free tool for this) I tested a batch that looks like this:

    <Batch PreCalc='TRUE' OnError='Continue'>
       <Method ID='1' Cmd='Delete'>
          <Field Name='ID'>108</Field>
          <Field Name="FileRef">http://server/Shared Documents/Stages.xml</Field>
       </Method>
    </Batch> 

    And was able to delete my file successfully. The interesting thing was, originally my URL was encoded -  Shared%20Documents instead of Shared Documents - and the query returned an error of "Invalid file name". So maybe check your URL variable?

    Hilary Stoupa

  • 01-08-2016 12:26 PM In reply to

    Re: UpdateListItem web service not working for "Delete" but working for "Update"

     Hi Hilary,

     I have checked the URL and I finally hardcoded as well, "<Method ID=\"1\" Cmd=\"Delete\"><Field Name=\"ID\">258</Field><Field Name=\"FileRef\">'http://**********/sites/subsite/Shared Documents/item.xml'</Field></Method>" and "<Method ID=\"1\" Cmd=\"Delete\"><Field Name=\"ID\">258</Field><Field Name=\"FileRef\">'http://**********/sites/subsite/Shared%20Documents/item.xml'</Field></Method>"  both I have tried still same issue.

     The error message is "0x81020030Invalid file name.\n\nThe 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." 

    Thanks, 

    SK. 

    Suthar
  • 01-08-2016 12:52 PM In reply to

    Re: UpdateListItem web service not working for "Delete" but working for "Update"

    Hmmm. I'm not sure what else to suggest. I just tried this again with U2U in case the behavior was different for site collections (my initial test was at the server root), and it worked as anticipated. I'm going to try to attach a copy of the CAML Query Editor I use here (it is freeware, but I think the newer versions don't have the UpdateListItems method) so maybe you could try it to experiment with CAML and see what works for you? After you connect, find your list in the column on the left, right click and select UpdateListItems - then you can build using their interface or just paste in your own and test it. :)
    Hilary Stoupa

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.