0

我有以下代码来自http://ktskumar.wordpress.com/2009/03/03/upload-document-from-local-machine-to-sharepoint-library/使用 Web 服务将文档上传到共享点库。我已添加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”复制类。我该如何解决这个问题,或者有其他方法可以实现我的目标。

4

1 回答 1

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 并单击“添加引用”按钮以将 web 服务 url 包含到项目中。

于 2013-04-23T06:46:22.140 回答