gpt4 book ai didi

c# - 上传文件到共享点服务器

转载 作者:太空宇宙 更新时间:2023-11-03 20:27:12 25 4
gpt4 key购买 nike

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

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

现在我通过从安装了 sharepoint 的服务器复制文件来引用 dll 文件“Microsoft.SharePoint”(因为我运行上传应用程序的 PC 没有安装 sharepoint)当我尝试运行应用程序时我得到了以下错误:

“无法加载文件或程序集‘Microsoft.SharePoint.Library,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c’或其依赖项之一。系统找不到指定的文件。”

虽然我的 PC 上没有安装 Sharepoint 并且我无法安装它,但我该如何解决这个问题呢?

提前致谢,希望我的问题很清楚!

最佳答案

您不能使用 visual studio 在具有服务器对象模型的客户端计算机上开发 Sharepoint 解决方案。请检查 - 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

希望这对您有所帮助。

关于c# - 上传文件到共享点服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9973140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com