How do I download zip file in C#?
It's mainly because you use a StreamWriter : TextWriter
to handle a binary Zip file. A StreamWriter expects text and will apply an Encoding. And even the simple ASCII Encoder might try to 'fix' what it thinks are invalid line-endings.
You can replace all your code with:
using (var client = new WebClient())
{
client.DownloadFile("http://something", @"D:\Downloads\1.zip");
}
Note that for new code you should look at HttpClient instead of WebClient.
And then don't use using( ) { }
You could just use WebClient
for a 2-liner:
using(WebClient wc = new WebClient())
{
wc.DownloadFile(url, @"D:\Downloads\1.zip");
}