views:

515

answers:

2

Hi,

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.

Regards,

Jene

A: 

Answered here

F.Aquino
i am not getting class "CopySoapClient" class.And can i use this code for lower version of Sharepoint?
Jene
+1  A: 

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

 }
Preeti Singh
Thanx Preeti.Your code really helped me.But problem now i am facing is : Files are not getting Uploaded on "List".Above code only uploading file in Folder.
Jene