Sunday, May 30, 2010

Upload Files to Remote PC

Here first You have to create a folder in remote machine and You have to share that folder with other network users.

And then using following method you can upload files to the remote shared folder. public int FileUpload(string SourceFilepath)
{
try
{
WebClient client = new WebClient();

//Credential information for remote Mechine.-> here I used Username=erandika1986 and Password=123
NetworkCredential nc = new NetworkCredential("erandika1986", "123");

//Here we have to give destination information
Uri addy = new Uri(@"\\192.168.2.4\UploadDocs\" + fileName);

//Here we set the the credential information to the Webclient
client.Credentials = nc;

//upload the file from Source to the destination
client.UploadFile(addy, SourceFilepath);

return 1;

}
catch (Exception ex1)
{
MessageBox.Show(ex1.Message);
return 0;
}

}

No comments: