简体   繁体   English

如何以编程方式在Sharepoint中创建一个wiki页面(= item)?

[英]How to create a wiki page (=item) in Sharepoint programmatically?

how do I create a wiki page and add a title, as well as some content in sharepoint (via webservices)? 如何创建Wiki页面并添加标题,以及sharepoint中的一些内容(通过webservices)?

This is my SOAP message so far: 到目前为止,这是我的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>

It creates a new page, but it has no content and no title. 它会创建一个新页面,但它没有内容,也没有标题。

Grab a copy of SharePoint Manager it can show you heaps of interesting info. 获取SharePoint Manager的副本,它可以显示大量有趣的信息。

you want the Name field (it includes the ".aspx"). 你想要名字字段(它包括“.aspx”)。 The title field is not relevant in a wiki (blank), pages are indexed by thier name instead. 标题字段与维基(空白)无关,页面由其名称索引。

--update-- --update--

Using the copy.asmx allows you to upload a new document. 使用copy.asmx可以上传新文档。 The template page is a page that has been downloaded previously (it stores no information, equivalent to a layout page). 模板页面是先前已下载的页面(它不存储任何信息,相当于布局页面)。

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

}

Then you can call the lists.asmx to update the wikifield. 然后你可以调用lists.asmx来更新wikifield。 Note: I have not figure out how to rename a document once it has been uploaded using webservices. 注意:一旦使用webservices上传文档,我还没弄清楚如何重命名文档。

Dan Winter wrote a fantastic application that I think could provide some sample code, take a look at it here: Dan Winter编写了一个很棒的应用程序,我认为可以提供一些示例代码,请在此处查看:

WikiMigrator WikiMigrator

Or for more information, read his comprehensive blog posts . 或者有关更多信息,请阅读他的综合博客文章

If nothing else is working you should develop your own web service to provide this feature. 如果没有其他工作,您应该开发自己的Web服务来提供此功能。 The out-of-the-box options are notoriously limited in functionality but there is nothing stopping you from adding to them. 开箱即用的选项在功能方面是众所周知的,但没有什么能阻止你添加它们。

I would wrap Nat's solution into the web service code. 我会将Nat的解决方案包装到Web服务代码中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM