The easiest way to upload a document to sharepoint using web services

I want to upload to the selected document (from my system. I have a path with me). To the target path in Sharepoint (may be a list or folder).

I am accessing sharepoint remotely using web services (C #). I read various solutions, for example, using the CopyIntoItems method. But do not get a proper example for it (it is impossible to pass parameters correctly. An example is given in msdn)

Can someone help me get a simple and clear solution.

Example:

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

I just want to upload "SampleFile.txt" to Destination_Url.

+3
source share
1 answer

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

 }
+4
source

Source: https://habr.com/ru/post/1730225/


All Articles