March 2006 - Posts - Agni Reddy

InfoPath Dev

Agni Reddy

March 2006 - Posts

  • Delete File from SharePoint

    There are times when we want to delete a file in SharePoint. To do this we need to call UpdateListItems web method in the Lists.asmx SharePoint web service. This document goes into the details of how to delete a file present in a form library in SharePoint.

    Create InfoPath project:

    1. Open Visual Studio and create a new InfoPath project.
    2. Copy the following code into a text editor and save it as UpdateListItemsConfig.xml.

    <?xml version="1.0" encoding="utf-8" ?>
                <Method ID="1" Cmd="Delete">
                    <Field Name="ID"></Field>
                    <Field Name="FileRef"></Field>

    Change the red text to be the form library name where the file that needs to be deleted is present.

    Add the UpdateListItemsConfig.xml as a secondary data connection:

    1. Choose Data Connections from the Tools menu, and then click Add.
    2. In the Data Connection Wizard, select Receive Data, and then click Next.
    3. Select XML Document, and then click Next.
    4. Click Browse, locate and select the UpdateListItemsConfig.xml file, click Open, and then click Next.
    5. Click Finish, click Yes, and then click Close.

    Take UpdateListItems data connection:

    Follow the steps to add the UpdateListItems data connection to delete the file:

    1. Go to Tools->DataConnections and Click on "Add" button.
    2. Select Submit Data and click on "Next" button.
    3. Select WebService and Click on "Next" button.
    4. Enter the Webservice address.
      for eg: http://<sharepoint server name>/<subsite name>/_vti_bin/lists.asmx?WSDL"
    5. Select UpdateListItems and click on next.
    6. By default s0:listName will be selected.
    7. Click on the Modify Icon at the end of Field or group field.
    8. Select UpdateListItemsConfig in the Data source dropdown.
    9. Select LibraryName and Click OK.
    10. Select the Check Box Submit Data as a String.

    1. Select s0:Updates and click on the Modify Icon at the end of Field or group field.
    2. Select UpdateListItemsConfig in the Data source dropdown.
    3. Select Batch node under SharePointDelete node.
    4. Select XML Subtree, Including selected element as shown in the picture below.

    1. Click button, enter SharePointDelete as name and Click on Finish.

    Add code to call the SharePointDelete data connection:

    1. Open the following code into the FormCode.cs:

    private void deleteFile(string fileName)
        thisXDocument.GetDOM("UpdateListItemsConfig").selectSingleNode("/UpdateListItemsConfig/SharepointDelete/Batch/Method/Field[@Name = 'FileRef']").text = fileName; 
        WebServiceAdapter2 deleteFileFromSharepoint = (WebServiceAdapter2)thisXDocument.DataAdapters["SharePointDelete"];

    1. Pass the complete filepath to the Method for deleting the File
      Ex: http://serverName/sites/SharePointDelete/TestDelete.xml
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.