user79127
user79127

Reputation: 119

Download file using webclient

I try to download a file from https site and every time the file is saved to my machine it is only 1KB. The file is supposed to be 1MB. I am using Webclient.

string strFile = @"c:\myfile.txt";
WebClient wc = new WebClient();
wc.Credentials = new System.Net.NetworkCredential("userid", "pw");
wc.DownloadFile("https://www.mysite.come/myfile.txt", strFile);

Do I miss anything?

Upvotes: 0

Views: 11564

Answers (2)

Vasa Serafin
Vasa Serafin

Reputation: 306

It is your permissions mate, I am having the same problem, yet no one seems to want to help 100% of the way... By permissions I mean your OS is not allowing the file to be downloaded into the directory that is why it is only 1KB.

I have gotten somewhere with it incidentally, [PrincipalPermission(SecurityAction.Demand, Role = @"BUILTIN\Administrators")]

I will keep an eye on this thread because there is a tag that has to be added, that I have searched for but have not found as of yet, I will keep you up to date.

Upvotes: 1

ShinTakezou
ShinTakezou

Reputation: 9661

AFAIK WebClient by default does not put the User-Agent string, this could annoy servers; try

wc.Headers.Add("User-Agent", "XXX");

where you can pick up XXX from here.

Upvotes: 3

Related Questions