【问题标题】:How to create XML webparts using sharepoint web services?如何使用共享点 Web 服务创建 XML Webpart?
【发布时间】:2010-04-20 20:07:38
【问题描述】:

我有一个要使用 XSL 文件在 sharepoint 中呈现的 XML。我现在介绍如何使用 sharepoint 的对象模型执行此操作,但不知道如何使用 sharepoint Web 服务执行此操作。

即我想使用共享点 Web 服务创建 XML Web 部件。

是否可以使用共享点 Web 服务创建 XML Web 部件?如果是,怎么做?

【问题讨论】:

  • 我觉得你应该更准确一些,告诉我们你想做什么。

标签: sharepoint moss wss wss-3.0


【解决方案1】:

自己发现了如何去做。 :-)

WebPartPagesweb 服务的AddWebPart 方法是唯一可用于添加Web 部件并将其添加到页面的方法。

您只需要正确准备需要作为参数传递给methosd的Xml。此 XML 确定 WebPart 的类型及其属性。

对于 Xml WebPArt,我使用了以下 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>

并将这个 Xml 字符串传递给AddWebPart 方法:

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;
        }

MSDN 帮助仅提供了 ContentEditor Web 部件的示例。我搜索了一下并将其修改为 Xml Web 部件。 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-15
    • 2011-02-15
    • 1970-01-01
    • 2011-04-27
    • 1970-01-01
    相关资源
    最近更新 更多