Simplest way to Upload a document to sharepoint using web services

…衆ロ難τιáo~ 提交于 2019-12-10 10:11:28

问题


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

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.

Example:

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

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


回答1:


try this one

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

 }


来源:https://stackoverflow.com/questions/2147539/simplest-way-to-upload-a-document-to-sharepoint-using-web-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!