2012-04-02 74 views
0

我需要從我的電腦的文件上傳到遠程SharePoint服務器,我有下面的代碼的應用程序:上傳文件到SharePoint Server

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

         SPFolder myLibrary = oWeb.Folders[documentLibraryName]; 

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

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

         //Commit :: 
         myLibrary.Update(); 
        } 
       } 

現在我引用的DLL文件「Microsoft.SharePoint程序」通過從安裝sharepoint的服務器上覆制文件(因爲運行上傳應用程序的PC不安裝sharepoint)當我嘗試運行應用程序時出現以下錯誤:

「無法加載文件或程序集'Microsoft.SharePoint.Library,Version = 12.0.0.0,Culture = neutral,PublicKeyToken = 71e9bce111e9429c'或者一個的依賴關係。該系統找不到指定的文件。」

所以,我怎麼能雖然我沒有安裝在我的電腦SharePoint和我事先無法安裝?

由於解決了這個問題,希望我的問題是要清楚!

回答

5

您不能使用Visual Studio的開發與服務器對象模型客戶機上的SharePoint解決方案請檢查 - 。http://msdn.microsoft.com/en-us/library/ee554869.aspxhttp://msdn.microsoft.com/en-us/library/ee231582.aspx

但是你可以開發在客戶端使用客戶端對象模型機器通過參考來自sharepoint服務器的和Microsoft.Sharepoint.Client.Runtime

您可以查看這篇文章,看看你如何能做到同樣的使用客戶端對象模型 - http://www.codeproject.com/Articles/103503/How-to-upload-download-a-document-in-SharePoint-20

http://blogs.msdn.com/b/sridhara/archive/2010/03/12/uploading-files-using-client-object-model-in-sharepoint-2010.aspx

希望這有助於。

+1

我在您支持的鏈接中使用了鱈魚樣本,但仍然不能正常工作,發出類似「無法聯繫網站********」的錯誤,並且當我編寫根URL時,它給出以下錯誤「服務器錯誤500內部服務器錯誤「我如何解決它? – Shabrawy 2012-04-02 11:25:03

+0

您必須使用.net 3.5和build-64或「any cpu」。 – Flowerking 2012-04-02 11:44:09

+0

我正在使用.net 3.5並構建64位,但仍然無法工作在我身邊我有同樣的問題該怎麼辦? – Ahmy 2012-04-02 11:52:23