指定的参数超出了有效值的范围。参数名称:服务器相对URL

时间:2013-01-04 15:22:37

标签: sharepoint sharepoint-2010 sharepointdocumentlibrary

我正在尝试使用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)
}

1 个答案:

答案 0 :(得分:3)

这一行:

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"

David Sterling - http://davidmsterling.blogspot.com - http://www.sterling-consulting.com - http://www.sharepoint-blog.com