从外部应用程序将文件上载到共享点服务器



我的客户端请求从外部应用程序将文件上传到他的共享点服务器。所以我设计了一个windows应用程序,使用了客户端提供的Microsoft.sharepoint.dll,并使用了以下代码进行上传。

 Public Function UploadFileToSharepoint(ByVal pstrSourceFilePath As String, ByVal pstrTargeSPURL As String) As Boolean
    If Not File.Exists(pstrSourceFilePath) Then
        Throw New ArgumentException(String.Format("{0} does not exist", pstrSourceFilePath), "srcUrl")
    End If
    Dim site As SPWeb = New SPSite(pstrTargeSPURL).OpenWeb()
    Dim fStream As FileStream = File.OpenRead(pstrSourceFilePath)
    Dim contents(CInt(fStream.Length)) As Byte
    fStream.Read(contents, 0, CInt(fStream.Length))
    fStream.Close()
    EnsureParentFolder(site, pstrTargeSPURL)
    site.Files.Add(pstrTargeSPURL, contents)
    Return True
End Function

我可以编译它,但在运行应用程序时,我遇到了一个错误,如"无法加载或找到程序集"Microsoft.Sharepoint.Library.dll".

我的问题是:是否可以开发一个应用程序来创建文件夹结构并将文件上传到共享点服务器,而无需在机器上安装共享点,但只有共享点dll?

为我提供一种实现这种发展的方法。将来,我的应用程序将在未安装共享点服务器的计算机上运行。

卢比

是的,您可以使用客户端对象模型来实现这一点,只需在项目中引用Microsoft.SharePoint.Client即可。以下是如何在C#中做到这一点,VB.net应该没有太大区别。

ClientContext context = new ClientContext("http://mydomain");
Web web = context.Web;
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = System.IO.File.ReadAllBytes(@"C:MyFile.docx");
newFile.Url = "MyFile.docx"; 
List docs = web.Lists.GetByTitle("Documents");
Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);
context.Load(uploadFile);
context.ExecuteQuery();

您应该研究如何使用SharePoint客户端对象模型(CSOM)。这将允许您从客户端与SharePoint进行交互。

更多信息,请点击-->http://msdn.microsoft.com/en-us/library/office/ee535451(v=office.14).aspx?cs save lang=1&cs lang=vb#code-snippet-1

最新更新