Compartilhar via


WebPartPagesWebService.DeleteWebPart Method

Deletes a dynamic Web Part from a Web Part Page.

Namespace:  [Webpartpages Web service]
Web service reference: http://Site/_vti_bin/Webpartpages.asmx

Syntax

'Declaration
<SoapDocumentMethodAttribute("https://microsoft.com/sharepoint/webpartpages/DeleteWebPart", RequestNamespace := "https://microsoft.com/sharepoint/webpartpages",  _
    ResponseNamespace := "https://microsoft.com/sharepoint/webpartpages",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Sub DeleteWebPart ( _
    pageUrl As String, _
    storageKey As Guid, _
    storage As Storage _
)
'Usage
Dim instance As WebPartPagesWebService
Dim pageUrl As String
Dim storageKey As Guid
Dim storage As Storage

instance.DeleteWebPart(pageUrl, storageKey, _
    storage)
[SoapDocumentMethodAttribute("https://microsoft.com/sharepoint/webpartpages/DeleteWebPart", RequestNamespace = "https://microsoft.com/sharepoint/webpartpages", 
    ResponseNamespace = "https://microsoft.com/sharepoint/webpartpages", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public void DeleteWebPart(
    string pageUrl,
    Guid storageKey,
    Storage storage
)

Parameters

  • pageUrl
    Type: System.String

    A string containing the URL of the page containing the Web Part.

  • storageKey
    Type: System.Guid

    A GUID that identifies of the Web Part.

Remarks

The DeleteWebPart method is used to delete a Web Part. Deleting a Shared Web Part, when storage is set to Personal, will throw the exception "Cannot delete Shared Web Part".

To access the WebPartPagesWebService service and its methods, set a Web reference to http://Virtual_Server_Name:Port_Number/_vti_adm/WebPartPages.asmx.

Examples

The following code example shows a locally defined DeleteWebPart method that takes a GUID of a Web Part as an argument and deletes the Web Part from a Web Part Page by calling the DeleteWebPart method of the Web Part Pages service through a proxy. This code example and the proxy are part of a larger example provided for the Web Part Pages service.

Private Sub DeleteWebPart(guidVal As String)
    ' NOTE: The Web Service we are using is defined on MyServer/_vti_bin
    ' Declare and initialize a variable for the WebPartPages Web Service.
    Dim svc = New Microsoft.Samples.WebPartPagesSvcClient.WebpartpagesSvc.WebPartPagesWebService()
         
    ' Authenticate the current user by passing their default
    ' credentials to the Web Service from the system credential cache.
    svc.Credentials = System.Net.CredentialCache.DefaultCredentials
        
    Dim pageUrl As String = "http://MyServer/Shared%20Documents/SampleStart.aspx"
    ' The GUID represents the Web Part ID being deleted
    Dim storageKey As New Guid(guidVal)
    Try
        svc.DeleteWebPart(pageUrl, storageKey, WebpartpagesSvc.Storage.Shared)
            Console.WriteLine("Part [{0}] has been deleted from page [{1}]" + ControlChars.Lf, guidVal, pageUrl)
        Catch er As Exception
            Console.WriteLine("Error: Part [{0}] was not deleted." + ControlChars.Lf + " {1}", guidVal, er.Message)
    End Try
End Sub 'DeleteWebPart
private void DeleteWebPart (string guidVal)
{
    // NOTE: The Web Service we are using is defined on MyServer/_vti_bin.

    // Declare and initialize a variable for the WebPartPages Web Service.
    WebpartpagesSvc.WebPartPagesWebService svc = new Microsoft.Samples.WebPartPagesSvcClient.WebpartpagesSvc.WebPartPagesWebService();
    // Authenticate the current user by passing their default
    // credentials to the Web Service from the system credential cache.
    svc.Credentials = System.Net.CredentialCache.DefaultCredentials;
    string pageUrl = "http://MyServer/Shared%20Documents/SampleStart.aspx";

    // The GUID represents the Web Part ID being deleted.
    Guid storageKey = new Guid(guidVal);  
    try 
    {
        svc.DeleteWebPart(pageUrl, storageKey, WebpartpagesSvc.Storage.Shared);
        Console.WriteLine("Part [{0}] has been deleted from page [{1}]\n", guidVal, pageUrl);
    }
    catch(Exception er)
    {
        Console.WriteLine("Error: Part [{0}] was not deleted.\n {1}", guidVal, er.Message);
    }
}

SOAP Request Format   The following is a sample SOAP 1.1 request. The placeholders shown need to be replaced with actual values.

POST /_vti_bin/webpartpages.asmx HTTP/1.1
Host: Server_Name
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "https://microsoft.com/sharepoint/webpartpages/DeleteWebPart"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <DeleteWebPart xmlns="https://microsoft.com/sharepoint/webpartpages">
      <pageUrl>string</pageUrl>
      <storageKey>guid</storageKey>
      <storage>None or Personal or Shared</storage>
    </DeleteWebPart>
  </soap:Body>
</soap:Envelope>

SOAP Response Format   The following is a sample SOAP 1.1 response. The placeholders shown will be replaced with actual values.

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <DeleteWebPartResponse xmlns="https://microsoft.com/sharepoint/webpartpages" />
  </soap:Body>
</soap:Envelope>

See Also

Reference

WebPartPagesWebService Class

WebPartPagesWebService Members

Webpartpages Web Service