Compartilhar via


WebPartPagesWebService.GetWebPart Method

Returns the XML data for a dynamic Web Part.

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

Syntax

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

returnValue = instance.GetWebPart(pageurl, _
    storageKey, storage)
[SoapDocumentMethodAttribute("https://microsoft.com/sharepoint/webpartpages/GetWebPart", RequestNamespace = "https://microsoft.com/sharepoint/webpartpages", 
    ResponseNamespace = "https://microsoft.com/sharepoint/webpartpages", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public string GetWebPart(
    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 the Web Part

Return Value

Type: System.String
A string containing the XML for a Web Part to include the type and assembly name fields.

Remarks

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 GetWebPart method that takes a GUID of a Web Part as an argument and obtains information about that Web Part by calling the GetWebPart method of the Web Part Pages service through a proxy. It then displays information about the Web Part. This code example and the proxy are part of a larger example provided for the Web Part Pages service.

Private Function GetWebPart(guidVal As String) 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"
    ' Explain that storagekey is a misnomer, the GUID represents the Web Part ID you are retreiving
    Dim storageKey As New Guid(guidVal)
    Dim result As String = svc.GetWebPart(pageUrl, storageKey, WebpartpagesSvc.Storage.Shared)
    Console.WriteLine("Result is: " + ControlChars.Lf + " {0}" + ControlChars.Lf, result)
    ' result looks like: 
    '
    '    <?xml version=\"1.0\" encoding=\"utf-16\"?>\n
    '    <WebPart xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"     '        xmlns=\"https://schemas.microsoft.com/WebPart/v2\">
    '    <Title>Announcements</Title>
    '    <FrameType>Default</FrameType>
    '    <Description>Use the Announcements list to post messages on the home page of your site.</Description>
    '    <IsIncluded>true</IsIncluded>
    '    <ZoneID>Footer</ZoneID>...
    '    <ListViewXml xmlns=\"https://schemas.microsoft.com/WebPart/v2/ListView\">&lt;View Name=\"{ECF376F0-ACCD-444D-AE50-307E5E547DF5}\" Type=\"HTML\"
    '        Hidden=\"TRUE\" DisplayName=\"\" Url=\"Shared Documents/SampleStart.aspx\" 
    '    BaseViewID=\"0\"&gt;&lt;ViewHeader&gt;&lt;HTML&gt;&lt;![CDATA[&lt;TABLE width=\"100%\" cellspacing=0 cellpadding=0 
    '        border=0&gt;]]&gt;&lt;/HTML&gt;&lt;HTML&gt;&lt;![CDATA[&lt;SCRIPT&gt;\nctx = new ContextInfo();\nctx.listBaseType =
    '        ]]&gt;&lt;/HTML&gt;&lt;ListProperty Select=\"BaseType\"/&gt;&lt;HTML&gt;&lt;![CDATA[;\nctx.listTemplate = ]]&gt;&l
    '    ...
    '
    Return result
End Function 'GetWebPart
private string GetWebPart (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";
        // Explain that storagekey is a misnomer, the GUID represents the Web Part ID you are retreiving
        Guid storageKey = new Guid(guidVal);
        string result = svc.GetWebPart(pageUrl, storageKey, WebpartpagesSvc.Storage.Shared);
        Console.WriteLine("Result is: \n {0}\n",result);
        /* result looks like: 
          <?xml version=\"1.0\" encoding=\"utf-16\"?>\n
          <WebPart xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"https://schemas.microsoft.com/WebPart/v2\">
          <Title>Announcements</Title>
          <FrameType>Default</FrameType>
          <Description>Use the Announcements list to post messages on the home page of your site.</Description>
          <IsIncluded>true</IsIncluded>
          <ZoneID>Footer</ZoneID>...
          <ListViewXml xmlns=\"https://schemas.microsoft.com/WebPart/v2/ListView\">&lt;View Name=\"{ECF376F0-ACCD-444D-AE50-307E5E547DF5}\" Type=\"HTML\" Hidden=\"TRUE\" DisplayName=\"\" Url=\"Shared Documents/SampleStart.aspx\" 
BaseViewID=\"0\"&gt;&lt;ViewHeader&gt;&lt;HTML&gt;&lt;![CDATA[&lt;TABLE width=\"100%\" cellspacing=0 cellpadding=0 
0&gt;]]&gt;&lt;/HTML&gt;&lt;HTML&gt;&lt;![CDATA[&lt;SCRIPT&gt;\nctx = new ContextInfo();\nctx.listBaseType = ]]
gt;&lt;/HTML&gt;&lt;ListProperty Select=\"BaseType\"/&gt;&lt;HTML&gt;&lt;![CDATA[;\nctx.listTemplate = ]]&gt;&l
          ...
        */
        return result;
      }

See Also

Reference

WebPartPagesWebService Class

WebPartPagesWebService Members

Webpartpages Web Service