2011-07-26 36 views
0

這是我第一次與分享點2010一起工作,我需要一個簡單的方法來上傳文件共享點2010務實的我已經找到它,但總是有一個假的錯誤,我想一個簡單而明確的方式來做到這一點使用c#與分享點2010 在此先感謝:)上傳文件到分享點2010文檔庫

回答

0

您需要嘗試的代碼。沒有人爲你的情況提供完美的代碼,可能是他們把「我的方法」或我的「參數」。任何方式,您可以使用此:

String fileToUpload = @"C:\YourFile.txt"; 
     String sharePointSite = "http://yoursite.com/sites/Research/"; 
     String documentLibraryName = "Shared Documents"; 

     using (SPSite oSite = new SPSite(sharePointSite)) 
     { 
      using (SPWeb oWeb = oSite.OpenWeb()) 
      { 
       if (!System.IO.File.Exists(fileToUpload)) 
        throw new FileNotFoundException("File not found.", fileToUpload);      

       SPFolder myLibrary = oWeb.Folders[documentLibraryName]; 

       // Prepare to upload 
       Boolean replaceExistingFiles = true; 
       String fileName = System.IO.Path.GetFileName(fileToUpload); 
       FileStream fileStream = File.OpenRead(fileToUpload); 

       // Upload document 
       SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceExistingFiles); 

       // Commit 
       myLibrary.Update(); 
      } 
     } 

你可以找到我的博客文章:
http://eslamsoliman.blogspot.com/2011/05/how-to-upload-file-to-share-point.html

+0

感謝eslam我要嘗試,我知道這樣的事情,問題是我沒有與分享點前 –

+0

偉大:)我在你的博客搜索之前,但我沒有找到它,因爲它沒有分類 –

相關問題