我需要使用客户端对象模型将新文档链接添加到文档库。我怀疑我可以复制“文档链接”项目中使用的.apSX文件的格式,并将其作为普通文件上传,但我希望有一种更整洁的方式。

因此,我想做的与下面的代码示例相同,但是我不想创建一个新文档,而要创建一个新的链接到文档。

ClientContext context = new ClientContext("http://wdev2008:22880");
context.Load(context.Web);
List list = context.Web.Lists.GetByTitle("Test Doc Link Library");
context.Load(list);
context.ExecuteQuery();

FileCreationInformation fileCreateInfo = new FileCreationInformation();
fileCreateInfo.Content = new byte[] { 0x33 };
fileCreateInfo.Url = "zerobyte";
File file = list.RootFolder.Files.Add(fileCreateInfo);
context.Load(file);
context.ExecuteQuery();

更新:根据该论坛上的MOD,我不允许在单独的问题中询问如何使用Web服务执行此操作,因此我将在此问题上更改标题,标签和内容。有谁知道如何使用SharePoint Web服务或服务器端控件或其他任何内容进行插入?

有帮助吗?

解决方案

事实证明,这可以完成,但是有点黑客,涉及获取.aspx文件SharePoint的副本用于文档链接并进行字符串搜索并在其上进行替换 在SharePoint文档库中编程中创建“指向文档链接”项目.

我为使用客户端对象模型定制了示例:

 string docLinkTemplate = null;
 using (System.IO.StreamReader sr = new System.IO.StreamReader("SharePointDocLinkTemplate.txt"))
 {
     docLinkTemplate = sr.ReadToEnd();
 }

 string docLink = "http://myserver/test.doc";
 docLinkTemplate = String.Format(docLinkTemplate, docLink);

 FileCreationInformation fileCreateInfo = new FileCreationInformation();
 fileCreateInfo.Content = Encoding.UTF8.GetBytes(docLinkTemplate);
 fileCreateInfo.Url = "testlinkfordoc.doc.aspx";
 File file = list.RootFolder.Files.Add(fileCreateInfo);
 ListItem fileListItem = file.ListItemAllFields;
 fileListItem["ContentType"] = "Link to a Document";
 FieldUrlValue urlValue = new FieldUrlValue();
 urlValue.Description = "Link to doc test";
 urlValue.Url = docLink;
 fileListItem["URL"] = urlValue;
 context.Load(file);
 context.ExecuteQuery();

(希望mod不会再认为这个答案了。怜悯这些编程网站上的mod不必在开始施加重量之前就获得stackoverflow代表。)

许可以下: CC-BY-SA归因
scroll top