2010-01-27 89 views
3

我想上传到选定的文档(从我的系统中获取,我有它的路径)。 到Sharepoint上的目标路径(可能是列表或文件夹)。使用Web服务将文档上传到Sharepoint的最简单方法

我正在使用Web服务(C#)远程访问SharePoint。 我通过使用CopyIntoItems方法读取各种解决方案。 但没有得到正确的例子(无法正确传递参数。在msdn上给出的例子)

任何人都可以帮助我得到简单易懂的解决方案。

实施例:

Source_FileUrl = “C:/SampleFile.txt”; Desination_Url =“http://MyServer/Site/List/Folder”;

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

回答

4

试试这个

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

} 
+0

感谢名单Preeti。 你的代码真的帮了我。 但现在我面临的问题是:文件没有上传到“列表”上。 以上代码仅上传文件夹中的文件。 – Preeti 2010-01-30 05:39:47

+0

你有这个解决方案..? – Arshad 2015-08-20 06:22:15

相关问题