Share via


Lists.DeleteAttachment method

Removes the attachment from the specified list item.

Namespace:  WebSvcLists
Assembly:  STSSOAP (in STSSOAP.dll)

Syntax

'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/sharepoint/soap/DeleteAttachment", RequestNamespace := "https://schemas.microsoft.com/sharepoint/soap/",  _
    ResponseNamespace := "https://schemas.microsoft.com/sharepoint/soap/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Sub DeleteAttachment ( _
    listName As String, _
    listItemID As String, _
    url As String _
)
'Usage
Dim instance As Lists
Dim listName As String
Dim listItemID As String
Dim url As String

instance.DeleteAttachment(listName, listItemID, _
    url)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/sharepoint/soap/DeleteAttachment", RequestNamespace = "https://schemas.microsoft.com/sharepoint/soap/", 
    ResponseNamespace = "https://schemas.microsoft.com/sharepoint/soap/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public void DeleteAttachment(
    string listName,
    string listItemID,
    string url
)

Parameters

  • listName
    Type: System.String

    A string that contains either the title or GUID for the list.

  • listItemID
    Type: System.String

    A string that contains the ID of the item to delete. This value does not correspond to the index of the item within the collection of list items.

  • url
    Type: System.String

    A string that contains the absolute URL for the attachment, as follows: https://Server_Name/Site_Name/Lists/List_Name/Attachments/Item_ID/FileName.

Remarks

The URL to the attachment can be returned by using the GetAttachmentCollection method.

To access the Lists service and its methods, set a Web reference to https://Server_Name/[sites/][Site_Name/]_vti_bin/Lists.asmx.

Examples

The following code example deletes all the attachments for a specified item in a list on the current site.

This example requires that a using (Visual C#) or Imports (Visual Basic) directive be included for the System.Xml namespace.

Dim listService As New Web_Reference_Folder.Lists()
listService.Credentials = System.Net.CredentialCache.DefaultCredentials

Dim ndAttach As XmlNode = 
    listService.GetAttachmentCollection("List_Name", "1")
Dim ndsAttach As XmlNodeList = ndAttach.ChildNodes
Dim i As Integer

For i = 0 To ndsAttach.Count - 1

    Dim delUrl As String = ndsAttach(i).InnerText

    listService.DeleteAttachment("List_Name", "1", delUrl)

Next i
Web_Reference_Folder.Lists listService = new Web_Reference_Folder.Lists();
listService.Credentials= System.Net.CredentialCache.DefaultCredentials;

XmlNode ndAttach = 
    listService.GetAttachmentCollection("List_Name", "1");
XmlNodeList ndsAttach = ndAttach.ChildNodes;

for (int i=0; i<ndsAttach.Count; i++)
{
    string delUrl = ndsAttach[i].InnerText;
    listService.DeleteAttachment("List_Name", "1", delUrl);
}

See also

Reference

Lists class

Lists members

WebSvcLists namespace