【问题标题】:Upload document from Local Machine to SharePoint 2013 Library using WebService使用 WebService 将文档从本地计算机上传到 SharePoint 2013 库
【发布时间】:2013-10-17 21:08:33
【问题描述】:

我有来自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”复制类。我该如何解决这个问题,或者有其他方法可以实现我的目标。

【问题讨论】:

  • 我认为 asmx 网络服务在 SP 2013 中是 deprecated
  • 这里不是很清楚你想做什么...所以用户会去Sharepoint然后点击某个地方浏览他的本地文件夹选择一个文件,然后它会上传文件到共享点?如果这就是你想要实现的原因,那么你可能想看看这个:SharepointPlus createFile;您必须使用 [html5rocks.com/en/tutorials/file/dndfiles/](HTML5 File API) 或旧浏览器的 Flash 解决方案...如果这不是您想要做的,请再次解释:-)
  • 嗨,我遇到了类似的问题,你是怎么过来的?

标签: sharepoint sharepoint-2013


【解决方案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 包含到项目中。

【讨论】:

    猜你喜欢
    • 2019-02-21
    • 1970-01-01
    • 2013-09-21
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 2013-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多