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);
}
}
}
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?