将文件上传到sharepoint服务器

时间:2012-04-02 08:32:27

标签: c# sharepoint uploading

我需要将文件从我的PC上传到远程sharepoint服务器,我有一个带有以下代码的应用程序:

 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而且我无法安装它?

提前致谢,希望我的问题要明确!。

1 个答案:

答案 0 :(得分:5)

您不能使用visual studio在具有服务器对象模型的客户端计算机上开发Sharepoint Solutions。请检查 - http://msdn.microsoft.com/en-us/library/ee554869.aspxhttp://msdn.microsoft.com/en-us/library/ee231582.aspx

但是,您可以通过引用sharepoint服务器中的Microsoft.Sharepoint.ClientMicrosoft.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

希望这有帮助。