WEBcLIENT pROBLEM
C#
1
Posts
1
Posters
0
Views
1
Watching
-
Hello Every 1. I have a strange problem with webclient. I have the following method in a class created to download files from a website. I download files sequentially i.e download one file dispose the download class object then create a new object and call the download method and so on....
public void DownloadVideo() { try { ///The WebClient object that will download the file WebClient wcDownload = new WebClient(); // Create a request to the file we are downloading webRequest = (HttpWebRequest)WebRequest.Create(_VideoUrl); // Set default authentication for retrieving the file webRequest.Credentials = CredentialCache.DefaultCredentials; // Retrieve the response from the server webResponse = (HttpWebResponse)webRequest.GetResponse(); //check if the webresponse is ok if (webResponse.ResponseUri.ToString() != "http://www.xyz.com/error.htm") { // Ask the server for the file size and store it Int64 fileSize = webResponse.ContentLength; // Open the URL for download strResponse = wcDownload.OpenRead(_VideoUrl); // Create a new local file stream strLocal = new FileStream(_VideoPath, FileMode.Create, FileAccess.Write, FileShare.None); // It will store the current number of bytes we retrieved from the server int bytesSize = 0; // A buffer for storing and writing the data retrieved from the server byte[] downBuffer = new byte[2048]; // Loop through the buffer until the buffer is empty while ((bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0) { // Write the data from the buffer to the local hard drive strLocal.Write(downBuffer, 0, bytesSize); UpdateVideoProgressEventArgs uvpea = new UpdateVideoProgressEventArgs(strLocal.Length, fileSize); UpdateVideoProgressEvent(this, uvpea); } }//end of second if }//end of try catch (Exception exp) { MessageBox.Show("Error in startDownload due to : " + exp.Mess