2

我正在尝试使用 MVC 从 SharePoint 文档库下载文档,但是每当我尝试运行我的代码时,都会出现上述错误。我是 SharePoint 的新手,所以请善待。这是我的代码:

网络助手:

public Stream DownloadDocument(string SiteURL, string documentName)
{
  ListItem item = GetDocumentFromSP(documentName);

  if (item != null) {
    using (ClientContext clientContext = new ClientContext(SiteUrl)) {
      FileInformation fileInformation = 
        Microsoft.SharePoint.Client.File.OpenBinaryDirect(
          clientContext, 
          item["My Document.docx"].ToString()
        );

      return fileInformation.Stream;
    }
  }

  return null;
}

控制器:

public ActionResult Index() 
{
  Stream documentDownload = 
    WebHelper.DownloadDocument(
      "http://MySharePointServer/Docs/Forms/AllItems.aspx", 
      "My Document"
  );

  model.downloadedDoc = documentDownload;

  return view(model)
}
4

1 回答 1

4

这一行:

Microsoft.SharePoint.Client.File.OpenBinaryDirect(
          clientContext, 
          item["My Document.docx"].ToString()

错了,正确的语法是指定文件的服务器相对 URL:

public static FileInformation OpenBinaryDirect(
    ClientContext context,
    string serverRelativeUrl
)

您的行应如下所示:

Microsoft.SharePoint.Client.File.OpenBinaryDirect(
      clientContext, 
      "/My Document.docx"

大卫斯特林 - http://davidmsterling.blogspot.com - http://www.sterling-consulting.com - http://www.sharepoint-blog.com

于 2013-01-05T20:43:25.990 回答