2013-01-04 30 views
1

我嘗試使用MVC從SharePoint文檔庫下載文檔,但是每當我嘗試運行我的代碼時,都會收到上述錯誤。我對SharePoint很陌生,所以請好起來。這裏是我的代碼:指定的參數超出有效值的範圍。參數名稱:服務器相對URL

網絡幫手:

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

回答

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" 

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

+0

這個工作。不能相信我無法爲自己解決這個問題 –

+2

有時你可以盯着某些東西,而不是通過樹木看到森林! –

相關問題