【问题标题】:Simplest way to Upload a document to sharepoint using web services使用 Web 服务将文档上传到共享点的最简单方法
【发布时间】:2014-07-10 17:53:15
【问题描述】:

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

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

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

例子:

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

只想在 Destination_Url 上上传“SampleFile.txt”。

【问题讨论】:

    标签: c# sharepoint-2007


    【解决方案1】:

    试试这个

    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);
    
     }
    

    【讨论】:

    • 感谢 Preeti。你的代码真的帮助了我。但现在我面临的问题是:文件没有在“列表”上上传。以上代码只上传文件夹中的文件。
    • 你有这个解决方案..?
    猜你喜欢
    • 2012-04-15
    • 2021-08-29
    • 1970-01-01
    • 1970-01-01
    • 2013-09-21
    • 1970-01-01
    • 2019-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多