I have an XML to be rendered in sharepoint using a XSL file. I now the how to do this using object model of sharepoint but don't how to do this using sharepoint web services.
i.e. 开发者_如何学GoI want to create XML web parts using sharepoint web services.
Is it possible to do create XML web parts using sharepoint web services? If yes, how?
Found out myself how to do it. :-)
The AddWebPart
method of WebPartPages
web service is the only method which can be used to add a web part and add it to a page too.
You only need to prepare the Xml properly which needs to be passed to the methosd as a parameter. This XML determines the type of WebPart and it's properties.
For Xml WebPArt, I used the following Xml:
<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">
<Assembly>Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.WebPartPages.XmlWebPart</TypeName>
<FrameType>None</FrameType>
<Title>XML Web Part</Title>
<XMLLink xmlns="http://schemas.microsoft.com/WebPart/v2/Xml">http://RootSite/sites/XYZ/Documents/ABC.xml</XMLLink>
<XML xmlns="http://schemas.microsoft.com/WebPart/v2/Xml" />
<XSLLink xmlns="http://schemas.microsoft.com/WebPart/v2/Xml">http://RootSite/sites/XYZ/Documents/ABC.xsl</XSLLink>
<XSL xmlns="http://schemas.microsoft.com/WebPart/v2/Xml" />
<PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/Xml" />
</WebPart>
And pass this Xml string to the AddWebPart
Method:
public static Guid WebPartPagesAddWebPart(string PageUrl, string WebPartXml, uint Storage)
{
// proxy object to call the Versions web service
WebPartPages.WebPartPagesWebService WebPartPagesWebService = new WebPartPages.WebPartPagesWebService();
// the user credentials to use
WebPartPagesWebService.Credentials = new NetworkCredential(UserName, Password, Domain);
WebPartPagesWebService.Url = sharePointHost + WebPartPagesServiceName;
// add the new web part to the page
Guid Result = WebPartPagesWebService.AddWebPart(PageUrl, WebPartXml, (WebPartPages.Storage)Storage);
// dispose the web service object
WebPartPagesWebService.Dispose();
return Result;
}
The MSDN help only gave a example for ContentEditor web part. I searched a bit and modified it for Xml web part. :)
精彩评论