Skip to content

Using WebClient to upload a file to Web

toanhoi bui

Asked Mar 30, 2011, 7:20 AM EDT3 answers
Share
LinkedInX
Hello, everybody.I try to wirite a project to upload a file to Web using Web client  by C#.But This code does not run.
WebClient webClient = new WebClient();
    string webAddress = null;
    try
    {
        webAddress = @"http://myCompany/ShareDoc/";;

        webClient.Credentials = CredentialCache.DefaultCredentials;

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

        webClient.UploadFile(webAddress + logFileName, "PUT", logFileName);
        webClient.Dispose();
        webClient = null;
    }
Can you help me to fix this error?

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Suthish Nair
    0
    fix this error? post your error also. where you uploading the file, to website folder, sharepoint folder etc.. ?
    0
  • 0
    This error is not upload to web.You have a code to upload file to web?
    0
  • Suthish Nair
    0
    you didn't said where you uploading the file. web means what?
    0