使用WebService将文档从本地计算机上载到SharePoint 2013库

时间:2013-04-04 12:41:00

标签: sharepoint sharepoint-2013

我有http://ktskumar.wordpress.com/2009/03/03/upload-document-from-local-machine-to-sharepoint-library/的以下代码,可以使用网络服务将文档上传到sharepoint库。我添加了https://mysite.sharepoint.com/_vti_bin/Copy.asmx(此网站在sharepoint Online上)作为我的服务参考。

     //Copy WebService Settings
        string webUrl = "https://mySite.sharepoint.com";

        WSCopy.Copy copyService = new WSCopy.Copy();

        copyService.Url = webUrl + "/_vti_bin/copy.asmx";
        copyService.Credentials = System.Net.CredentialCache.DefaultCredentials;

        //Source and Destination Document URLs
        string sourceUrl = "http://localhost/Shared Documents/Sample.doc";
        string destinationUrl = "E:\\DocumentsSample.doc";

        //Variables for Reading metadata’s of a document
        WSCopy.FieldInformation fieldInfo = new WSCopy.FieldInformation();
        WSCopy.FieldInformation[] fieldInfoArray = { fieldInfo };
        WSCopy.CopyResult cResult1 = new WSCopy.CopyResult();
        WSCopy.CopyResult cResult2 = new WSCopy.CopyResult();
        WSCopy.CopyResult[] cResultArray = { cResult1, cResult2 };

        //Receive a Document Contents  into Byte array (filecontents)
        byte[] fileContents = new Byte[4096];
        uint copyresult = copyService.GetItem(sourceUrl, out fieldInfoArray, out fileContents);

        if (copyresult == 0)
        {
            Console.WriteLine("Document downloaded Successfully, and now it's getting saved in location " + destinationUrl);

            //Create a new file and write contents to that document
            FileStream fStream = new FileStream(destinationUrl, FileMode.Create, FileAccess.ReadWrite);
            fStream.Write(fileContents, 0, fileContents.Length);
            fStream.Close();

        }
        else
        {
            Console.WriteLine("Document Downloading gets failed...");
        }

        Console.Write("Press any key to exit...");
        Console.Read();

这里WSCopy是服务引用,在我的项目中找不到'WSCopy.Copy'副本类。我怎样才能解决这个问题,或者是否有另一种方法来实现我的目标。

1 个答案:

答案 0 :(得分:1)

参考这篇文章 http://www.ktskumar.com/blog/2009/03/upload-document-from-local-machine-to-sharepoint-library/

您必须在Web Reference中添加Web服务URL,而不是Service Reference。 在Visual Studio项目中,右键单击“引用”,然后选择“添加服务引用”。 在“添加服务引用”弹出窗口中,单击该框底部的“高级”按钮, 现在将打开“服务引用设置”弹出窗口,我们必须单击“添加Web引用”按钮。然后提供Web服务URL并单击“添加引用”按钮以将webservice URL包含在项目中。