Simple file download no longer works under .NET 2.0

  • Thread starter Thread starter ASI Tech
  • Start date Start date
A

ASI Tech

Guest
For years now I've had a simple .NET 2.0 program that downloads a single file from the web. Now it only creates a file with zero bytes. But if I change the target framework to .NET 4.6, it works as it always had. Mind you, I've made NO changes to the code. What could explain this? Thanks

using System;
using System.ComponentModel;
using System.Net;
using System.Windows.Forms;

namespace NewTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
StartDownload();
}

private void StartDownload()
{
using (WebClient client = new WebClient())
{
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);

// Starts the download
string destination = "Tools.exe";
string sourceURL = "https://mysite.com/download/Tools.exe";

client.DownloadFileAsync(new Uri(sourceURL), destination);
}
}

void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}

void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("Done");
}
}
}

Continue reading...
 

Similar threads

Back
Top