none
Error : An exception occurred during a WebClient request.

    Question

  • Hi,

    At first, i would say i'm french, so sorry for my bad english ! ;)


    So, I've been searching an answer for a long time but I didn't find, I really need your help.

    I'm trying to do an "auto downloader program". For exemple, I often have to download .NET Framework V4. So i would download it with my program. My function is the following :

    public void StartDownload()
            {
                try
                {
                    WebClient wc = new WebClient();
                    wc.DownloadFile("http://download.microsoft.com/download/1/B/E/1BE39E79-7E39-46A3-96FF-047F95396215/dotNetFx40_Full_setup.exe", IO.Path.GetTempPath());
                    wc.Dispose();
                }
                catch (Exception e)
                {
                    MessageBox.Show("Error : " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                }
            }



    But I have an exception : An exception occurred during a WebClient request.


    Can you help me ?

    Have a nice day !


    • Edited by Diuby Thursday, November 07, 2013 2:20 PM
    Thursday, November 07, 2013 2:19 PM

Answers

  • Proble is that you are just giving folder path as second argument to WebClient.DownloadFile method. But you have to provide a file name as well. So, below code should work for you,

    public void StartDownload()
    {
        try
        {
            WebClient wc = new WebClient();
            string filePath = @"http://download.microsoft.com/download/1/B/E/1BE39E79-7E39-46A3-96FF-047F95396215/dotNetFx40_Full_setup.exe";
            wc.DownloadFile(filePath, System.IO.Path.GetTempPath() + "\\" + System.IO.Path.GetFileName(filePath));
            wc.Dispose();
        }
        catch (Exception e)
        {
            MessageBox.Show("Error : " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
        }
    }

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Thursday, November 07, 2013 2:50 PM

All replies

  • Proble is that you are just giving folder path as second argument to WebClient.DownloadFile method. But you have to provide a file name as well. So, below code should work for you,

    public void StartDownload()
    {
        try
        {
            WebClient wc = new WebClient();
            string filePath = @"http://download.microsoft.com/download/1/B/E/1BE39E79-7E39-46A3-96FF-047F95396215/dotNetFx40_Full_setup.exe";
            wc.DownloadFile(filePath, System.IO.Path.GetTempPath() + "\\" + System.IO.Path.GetFileName(filePath));
            wc.Dispose();
        }
        catch (Exception e)
        {
            MessageBox.Show("Error : " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
        }
    }

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Thursday, November 07, 2013 2:50 PM
  • One big issue is that you only expose the Exception Message, wich is only 5% of the exception Information.

    The other 95% (that you propably need) are the inner exceptions and stack trace. Wich can be aquired by using Exception.toString() isnstead of Exception.Message.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.

    Thursday, November 07, 2013 2:56 PM