1

I want to upload a file securely from client machine to a webserver using C# client. It will be helpful to get some sample application of this. Also I want to know how can I achieve this with ssl certificate.

Thanks,

Abdul

Abdul
  • 321
  • 4
  • 22

1 Answers1

3
 WebClient webClient = new WebClient();
        string webAddress = null;
        try
        {
            webAddress = @"http://myCompany/ShareDoc/";

            webClient.Credentials = CredentialCache.DefaultCredentials;

            WebRequest serverRequest = WebRequest.Create(webAddress);
            WebResponse serverResponse;
            serverResponse = serverRequest.GetResponse();
            serverResponse.Close();

            webClient.UploadFile(webAddress + logFileName, "PUT", logFileName);
            webClient.Dispose();
            webClient = null;
        }
        catch (Exception error)
        {
            MessageBox.Show(error.Message);
        }
Hassan Boutougha
  • 3,871
  • 1
  • 17
  • 17
  • I'm very sorry, I didn't understand could you please explain it, also I need to upload file to webserver not downloading. – Abdul Aug 16 '12 at 05:10
  • sorry i read download file instead upload ;-) so i correct it – Hassan Boutougha Aug 16 '12 at 05:18
  • hope it's useful for https too..., anyway I will try. – Abdul Aug 16 '12 at 05:25
  • I have succeded https solution also with the help of the following link http://stackoverflow.com/questions/10822509/the-request-was-aborted-could-not-create-ssl-tls-secure-channel – Abdul Aug 16 '12 at 09:27
  • After a day of struggle this helped me realize the file name has to be appended to the URL. Thanks. – David May 22 '15 at 07:51