WebPartPagesWebService.GetWebPartProperties Method

Returns an XML string of all Web Parts associated with a Web Part Page.

Web Service: Web Part PagesWeb Reference: http://<Site>/_vti_bin/WebPartPages.asmx

Syntax

<SoapDocumentMethodAttribute("http://microsoft.com/sharepoint/webpartpages/GetWebPartProperties", RequestNamespace:="http://microsoft.com/sharepoint/webpartpages", ResponseNamespace:="http://microsoft.com/sharepoint/webpartpages", Use:=SoapBindingUse.Literal, ParameterStyle:=SoapParameterStyle.Wrapped)> _
Public Function GetWebPartProperties ( _
    pageUrl As String, _
    storage As Storage _
) As XmlNode

Dim instance As WebPartPagesWebService
Dim pageUrl As String
Dim storage As Storage
Dim returnValue As XmlNode

returnValue = instance.GetWebPartProperties(pageUrl, storage)
[SoapDocumentMethodAttribute("http://microsoft.com/sharepoint/webpartpages/GetWebPartProperties", RequestNamespace="http://microsoft.com/sharepoint/webpartpages", ResponseNamespace="http://microsoft.com/sharepoint/webpartpages", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)] 
public XmlNode GetWebPartProperties (
    string pageUrl,
    Storage storage
)

Parameters

  • pageUrl
    The URL of the page containing the Web Part.
  • storage
    A Storage value indicating how the Web Part is stored.

Return Value

SoapXmlElement XML string for all the Web Parts on a Web Part Page. This includes the GUIDs, Web Part properties and their values, and Web Part previews in HTML.

Remarks

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

Example

The following code example shows a locally defined GetWebPartProperties method that retrieves information for all the Web Parts on a Web Part Page by calling the GetWebPartProperties method of the Web Part Pages service through a proxy. It then displays the title, GUID, and type of each of the Web Parts. This code example and the proxy are part of a larger example provided for the Web Part Pages service.

Private Sub GetWebPartProperties()
    ' 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"
    ' Use GetWebPartProperties to retreive the ID for one of the Web Parts on the source page
    Dim resultNode As XmlNode = svc.GetWebPartProperties(pageUrl, WebpartpagesSvc.Storage.Shared)
    Console.WriteLine("The following Web Parts were found on page " + ControlChars.Lf + "{0}" + ControlChars.Lf, pageUrl)
    Dim node As XmlNode
    For Each node In  resultNode
        Dim partTitle As String = node("Title").InnerText
        Dim partId As String = node.Attributes("ID").InnerText
        Dim partTypeName As String = node("TypeName").InnerText
            
        Console.WriteLine("Part '{0}' with ID [{1}] " + ControlChars.Lf + ControlChars.Tab + "is of type {2}" + ControlChars.Lf, partTitle, partId, partTypeName)
    Next node 
        Console.WriteLine("-----Hit enter-----")
        Console.ReadLine()
  End Sub 'GetWebPartProperties

  ' XML structure looks like (example of a Contacts Web Part on a page)
  '
  '<SoapXmlElement xmlns="http://microsoft.com/sharepoint/webpartpages">
  '<WebParts>
  '<WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/WebPart/v2" ID="b4523d8e-12f3-410a-99e1-0b915ba90b73">
  '<Title>Contacts</Title> 
  '<FrameType>Default</FrameType> 
  '<Description>Use the Contacts list for information about people that your team works with.</Description> 
  '<IsIncluded>true</IsIncluded> 
  '<ZoneID>LeftColumn</ZoneID> 
  '<PartOrder>1</PartOrder> 
  '<FrameState>Normal</FrameState> 
  '<Height /> 
  '<Width /> 
  '<AllowRemove>true</AllowRemove> 
  '<AllowZoneChange>true</AllowZoneChange> 
  '<AllowMinimize>true</AllowMinimize> 
  '<IsVisible>true</IsVisible> 
  '<DetailLink>http://MyServer/Lists/Contacts/AllItems.aspx</DetailLink> 
  '<HelpLink>http://MyServer/_vti_bin/help/1033/sts/html/dlistwps.htm</HelpLink> 
  '<Dir>Default</Dir> 
  '<PartImageSmall /> 
  '<MissingAssembly /> 
  '<PartImageLarge>http://MyServer/_layouts/images/itcontct.gif</PartImageLarge> 
  '<IsIncludedFilter /> 
  '<ExportControlledProperties>false</ExportControlledProperties> 
  '<ConnectionID>00000000-0000-0000-0000-000000000000</ConnectionID> 
  '<Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly> 
  '<TypeName>Microsoft.SharePoint.WebPartPages.ListViewWebPart</TypeName> 
  '<ListName xmlns="http://schemas.microsoft.com/WebPart/v2/ListView">{199A4AEA-A573-40CB-BB3C-7A66C0375104}</ListName> 
  '<ListViewXml xmlns="http://schemas.microsoft.com/WebPart/v2/ListView">
     '<View Name="{B4523D8E-12F3-410A-99E1-0B915BA90B73}" Type="HTML" Hidden="TRUE" DisplayName="" Url="Shared Documents/SampleStart.aspx" BaseViewID="0">
     '<GroupByHeader><HTML></HTML></Toolbar><ViewFields><FieldRef Name="LinkTitleNoMenu"/><FieldRef Name="FirstName"/>
     '<FieldRef Name="WorkPhone"/><FieldRef Name="Email"/></ViewFields><Query><OrderBy><FieldRef Name="Title"/><FieldRef Name="FirstName"/>
     '</OrderBy></Query></View></ListViewXml> 
  '<ViewFlag xmlns="http://schemas.microsoft.com/WebPart/v2/ListView">9</ViewFlag> 
  '</WebPart>
  '</SoapXmlElement>
private void GetWebPartProperties()
   {
     // 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";
        // Use GetWebPartProperties to retrieve the ID for one of the Web Parts on the source page
        XmlNode resultNode = svc.GetWebPartProperties(pageUrl, WebpartpagesSvc.Storage.Shared);
        Console.WriteLine("The following Web Parts were found on page \n{0}\n", pageUrl);
        foreach(XmlNode node in resultNode)
        {
          string partTitle = node["Title"].InnerText;
          string partId = node.Attributes["ID"].InnerText;
          string partTypeName = node["TypeName"].InnerText;
          Console.WriteLine("Part '{0}' with ID [{1}] \n\tis of type {2}\n", partTitle, partId, partTypeName);

        }
        Console.WriteLine("-----Hit enter-----");
        Console.ReadLine();
        /* XML structure looks like (example of a Contacts Web Part on a page)
          <SoapXmlElement xmlns="http://microsoft.com/sharepoint/webpartpages">
            <WebParts>
              <WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/WebPart/v2" ID="b4523d8e-12f3-410a-99e1-0b915ba90b73">
              <Title>Contacts</Title> 
              <FrameType>Default</FrameType> 
              <Description>Use the Contacts list for information about people that your team works with.</Description> 
              <IsIncluded>true</IsIncluded> 
              <ZoneID>LeftColumn</ZoneID> 
              <PartOrder>1</PartOrder> 
              <FrameState>Normal</FrameState> 
              <Height /> 
              <Width /> 
              <AllowRemove>true</AllowRemove> 
              <AllowZoneChange>true</AllowZoneChange> 
              <AllowMinimize>true</AllowMinimize> 
              <IsVisible>true</IsVisible> 
              <DetailLink>http://MyServer/Lists/Contacts/AllItems.aspx</DetailLink> 
              <HelpLink>http://MyServer/_vti_bin/help/1033/sts/html/dlistwps.htm</HelpLink> 
              <Dir>Default</Dir> 
              <PartImageSmall /> 
              <MissingAssembly /> 
              <PartImageLarge>http://MyServer//_layouts/images/itcontct.gif</PartImageLarge> 
              <IsIncludedFilter /> 
              <ExportControlledProperties>false</ExportControlledProperties> 
              <ConnectionID>00000000-0000-0000-0000-000000000000</ConnectionID> 
              <Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly> 
              <TypeName>Microsoft.SharePoint.WebPartPages.ListViewWebPart</TypeName> 
              <ListName xmlns="http://schemas.microsoft.com/WebPart/v2/ListView">{199A4AEA-A573-40CB-BB3C-7A66C0375104}</ListName> 
              <ListViewXml xmlns="http://schemas.microsoft.com/WebPart/v2/ListView">
                    <View Name="{B4523D8E-12F3-410A-99E1-0B915BA90B73}" Type="HTML" Hidden="TRUE" DisplayName="" Url="Shared Documents/SampleStart.aspx" BaseViewID="0">
                    <GroupByHeader><HTML></HTML></Toolbar><ViewFields><FieldRef Name="LinkTitleNoMenu"/><FieldRef Name="FirstName"/>
                    <FieldRef Name="WorkPhone"/><FieldRef Name="Email"/></ViewFields><Query><OrderBy><FieldRef Name="Title"/><FieldRef Name="FirstName"/>
                    </OrderBy></Query></View></ListViewXml> 
              <ViewFlag xmlns="http://schemas.microsoft.com/WebPart/v2/ListView">9</ViewFlag> 
             </WebPart>
           </SoapXmlElement>    
        */    
      }

See Also

Reference

WebPartPagesWebService Class
WebPartPagesWebService Members
Web Part Pages Web Service