2012-04-02 99 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

相关问题