toanhoi bui

toanhoi bui

  • NA
  • 70
  • 207.3k

Using WebClient to upload a file to Web

Mar 30 2011 11:20 AM
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?


Answers (3)