I have the following code for simple downloading a file using WebClient:

using System;
using System.Net;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DownloadManager
{
    public partial class Form1 : Form
    {
        public Form1()
        {

            InitializeComponent();

        }




        private void downloadbtn_Click(object sender, EventArgs e)
        {

            WebClient wc = new WebClient();

                wc.DownloadFile(this.downloadURL.Text, this.savePath.Text);



        }




    }
}

0ebd2d094acce1f0e3b48ae3114c83e7

Moreover, i have a form design:

a textbox to enter url (Name:downloadURL)

a textbox to set download path(Name:savePath)

a download button(Name:downloadbtn)

The issue is:

wc.DownloadFile(this.downloadURL.Text, this.savePath.Text);
returns

WebException unhandled

An exception occurred during a WebClient request.

How to fix it?

Recommended Answers

Assuming "E:\downloads" is a folder, "PathtoSave" should include the filename--not just the folder.

ex:

WebClient wc = new WebClient();

string localFilename = @"E:\downloads\myfile.txt";

wc.DownloadFile(downloadURL.Text, localFilename);

Resource:
Download Files from Web [C#]

Jump to Post

You haven't provided enough detail. What is the exception that you are receiving? What is the value of "downloadURL.Text"? Does the website require you to login to use it? Have you tried any other websites?

Jump to Post

All 5 Replies

But it still throwing the same exception!!!

You haven't provided enough detail. What is the exception that you are receiving? What is the value of "downloadURL.Text"? Does the website require you to login to use it? Have you tried any other websites?

What exception occured? This post is extremely vague, and I'd recommend explaining what errors/issues occured, not just "this issue occured, fix it please.

Have a great day!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.