【问题标题】:How to create a wiki page (=item) in Sharepoint programmatically?如何以编程方式在 Sharepoint 中创建 wiki 页面(=item)?
【发布时间】:2009-06-09 11:50:30
【问题描述】:

如何创建 wiki 页面并添加标题以及 sharepoint 中的一些内容(通过网络服务)?

到目前为止,这是我的 SOAP 消息:

  <soapenv:Body>
  <soap:UpdateListItems>

    <soap:listName>Cooking Wiki</soap:listName>

    <soap:updates>
     <Batch OnError="Continue">
      <Method ID="1" Cmd="New">   
       <Field Name="WikiField">Mix two eggs and a cup of milk.</Field>
      </Method>
     </Batch>
    </soap:updates>

   </soap:UpdateListItems>
  </soapenv:Body>

它创建了一个新页面,但它没有内容也没有标题。

【问题讨论】:

  • 您是否有权在 SharePoint 服务器上创建自己的 Web 服务?如果是这种情况,那么您可以访问整个 SharePoint 对象模型来创建您的 wiki 页面。如果这确实是您的选择,我也许可以为您拼凑一些示例代码。
  • 遗憾的是,我无法编写自己的 Web 服务,因为该解决方案必须在通用 Sharepoint 服务器上运行。

标签: sharepoint soap wiki caml


【解决方案1】:

获取SharePoint Manager 的副本,它可以向您展示大量有趣的信息。

您想要名称字段(它包括“.aspx”)。 标题字段在 wiki 中不相关(空白),页面由其名称索引。

--更新--

使用 copy.asmx 允许您上传新文档。模板页面是之前下载过的页面(不存储任何信息,相当于布局页面)。

private byte[] GetTemplatePage()
{
    FileStream fs = new FileStream("templatePage.aspx", FileMode.Open);
    byte[] fileContents = new byte[(int)fs.Length];
    fs.Read(fileContents, 0, (int)fs.Length);

    fs.Close();
    return fileContents;
}

private void UploadDoc(string pageName)
{
    byte[] wikiBytes = GetTemplatePage();

    string dest = "http://[website]/wiki/Wiki%20Pages/" + pageName + ".aspx";
    string[] destinationUrlArray = new string[] { dest };

    IntranetCopy.Copy copyService = new IntranetCopy.Copy();
    copyService.UseDefaultCredentials = true;
    copyService.Url = "http://[website]/wiki/_vti_bin/copy.asmx";

    IntranetCopy.FieldInformation fieldInfo = new IntranetCopy.FieldInformation();
    IntranetCopy.FieldInformation[] fields = { fieldInfo };

    IntranetCopy.CopyResult[] resultsArray;
    copyService.Timeout = 600000;

    uint documentId = copyService.CopyIntoItems(dest, destinationUrlArray, fields, wikiBytes, out resultsArray);

}

然后您可以调用 lists.asmx 来更新 wikifield。 注意:我还没有弄清楚如何在使用 web 服务上传文档后重命名它。

【讨论】:

  • 我已经安装了 Sharepoint Manager 并尝试了几乎所有属性:没有解决方案。 :-(
  • 是的,看起来 wiki 是一个非常特殊的文档库。
【解决方案2】:

【讨论】:

  • 谢谢。我已经知道了。我什至在文章中提到了 CopyService 的权宜之计。但这对我来说不是一个合适的解决方案,因为我需要从头开始创建页面。
【解决方案3】:

Dan Winter 编写了一个很棒的应用程序,我认为它可以提供一些示例代码,请看这里:

WikiMigrator

或了解更多信息,read his comprehensive blog posts

【讨论】:

  • 谢谢,我已经用它来了解 SOAP 调用中发生了什么。
【解决方案4】:

如果没有其他工作,您应该开发自己的 Web 服务来提供此功能。众所周知,开箱即用的选项功能有限,但没有什么能阻止您添加它们。

我会将Nat's solution 包装到网络服务代码中。

【讨论】:

  • 遗憾的是,我无法编写自己的 Web 服务,因为该解决方案必须在通用 Sharepoint 服务器上运行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-10
  • 1970-01-01
相关资源
最近更新 更多