使用 Web 服务将文档上传到共享点的最简单方法 [英] Simplest way to Upload a document to sharepoint using web services

查看:30
本文介绍了使用 Web 服务将文档上传到共享点的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上传到选定的文档(来自我的系统.我有它的路径).到 Sharepoint 上的目标路径(可能是列表或文件夹).

I want to upload to a Selected Document (from my system.I am having it's path with me). To a destination path on Sharepoint ( may be list or folder ).

我正在使用 Web 服务 (C#) 远程访问 sharepoint.我阅读了各种解决方案,例如使用 CopyIntoItems 方法.但没有得到正确的例子(无法正确传递参数.msdn 上给出的尝试示例)

I am accessing sharepoint remotely using web services (C#). I read various solutions like by using CopyIntoItems method. But not getting proper example for it ( unable to pass parameters properly.tried example given on msdn)

谁能帮我找到简单易懂的解决方案.

Can anyone help me out to get simple and understandable solution.

示例:

Source_FileUrl = "c:/SampleFile.txt";Desination_Url = "http://MyServer/Site/List/Folder";

Source_FileUrl = "c:/SampleFile.txt"; Desination_Url = "http://MyServer/Site/List/Folder";

只想上传 Destination_Url 上的SampleFile.txt".

Just want to upload "SampleFile.txt" on Destination_Url.

推荐答案

试试这个

try
    {

    //Copy WebService Settings 
    string webUrl           = "http://sharepointportal.ABC.com/";
    WSCopy.Copy copyService = new WSCopy.Copy();
    copyService.Url         = webUrl + "/_vti_bin/copy.asmx";
    copyService.Credentials = new NetworkCredential("username", "****", "Domain");

    //Declare and initiates the Copy WebService members for uploading 

    string sourceUrl        = "C:\\Work\\Ticket.Doc";   

    //Change file name if not exist then create new one     
    string[] destinationUrl    = { "http://sharepointportal.ABC.com/personal/username/Document Upload/Testing Document/newUpload.Doc" };

    WSCopy.CopyResult cResult1 = new WSCopy.CopyResult();

    WSCopy.CopyResult cResult2 = new WSCopy.CopyResult();

    WSCopy.CopyResult[] cResultArray = { cResult1, cResult2 };

    WSCopy.FieldInformation fFiledInfo = new WSCopy.FieldInformation();

    fFiledInfo.DisplayName = "Description";

    fFiledInfo.Type        = WSCopy.FieldType.Text;

    fFiledInfo.Value       = "Ticket";

    WSCopy.FieldInformation[] fFiledInfoArray = { fFiledInfo }; 

    FileStream strm = new FileStream(sourceUrl, FileMode.Open, FileAccess.Read); 

    byte[] fileContents = new Byte[strm.Length]; 

    byte[] r = new Byte[strm.Length];

    int ia = strm.Read(fileContents, 0, Convert.ToInt32(strm.Length));
    strm.Close();
    //Copy the document from Local to SharePoint 

    uint copyresult = copyService.CopyIntoItems(sourceUrl, destinationUrl, fFiledInfoArray, fileContents, out cResultArray); 

    MessageBox.Show("Suceess");  

  }
 catch (Exception ex)    
 { 
    MessageBox.Show(ex.Message);

 }

这篇关于使用 Web 服务将文档上传到共享点的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆