Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. WEBcLIENT pROBLEM

WEBcLIENT pROBLEM

Scheduled Pinned Locked Moved C#
helpcomsysadminsecurity
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    t4ure4n
    wrote on last edited by
    #1

    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
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups