3
Answers

Using WebClient to upload a file to Web

toanhoi bui

toanhoi bui

13y
2.9k
1
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)