c# - Download file and automatically save it to folder -
i'm trying make ui downloading files site. site have zip-files , these need downloaded directory entered user. however, can't succeed download file, opens temporary folder.
code:
private void webbrowser1_navigating(object sender, webbrowsernavigatingeventargs e) { e.cancel = true; string filepath = null; filepath = textbox1.text; webclient client = new webclient(); client.downloadfilecompleted += new asynccompletedeventhandler(client_downloadfilecompleted); client.downloadfileasync(e.url, filepath); }
full sourcecode: http://en.paidpaste.com/lqemiq
why not bypass webclient's file handling pieces altogether. perhaps similar this:
private void webbrowser1_navigating(object sender, webbrowsernavigatingeventargs e) { e.cancel = true; webclient client = new webclient(); client.downloaddatacompleted += new downloaddatacompletedeventhandler(client_downloaddatacompleted); client.downloaddataasync(e.url); } void client_downloaddatacompleted(object sender, downloaddatacompletedeventargs e) { string filepath = textbox1.text; file.writeallbytes(filepath, e.result); messagebox.show("file downloaded"); }
Comments
Post a Comment