Click here to Skip to main content
15,906,645 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends,
good morning all..


I have a question on downloading a file from the URL.My question is URL is not the direct path of the file we are going to download rather it calls some method which returns a open/save dialog. but my requirement is while am clicking on some button i need to get that file to local disk location.

To do this i used webclient but it is downloading html page to word document but i need word document only.

private void button1_Click(object sender, EventArgs e)
       {
           string downloadlink = webbrowser.Document.GetElementById("download").GetAttribute("href");
           WebClient client = new WebClient();
           client.DownloadFile(downloadlink, @"E:\Suresh_works\test.doc");
       }



in downloadlink am getting the path like this :: http://mydomain.com/view/download?uname=test&sid=123

when am copy and paste in browser it opens a dialog to choose the option open/save/cancel
i want that file to copy to my localdisk location in button click
Am working on webbrowser control

...........................

Thanks
SureshV
Posted
Updated 13-Mar-12 20:26pm
v5
Comments
hitech_s 14-Mar-12 2:18am    
any one while u r down voting u should give proper reason for that otherwise dont do such kind of things.. plz

1 solution

hi suresh ...

i think ur problem is "downloadlink" string ...

plz check this string value is giving correct path of the file u want to download.. it should be full server path of the file...

thnks....

Dhaval Patel
 
Share this answer
 
Comments
hitech_s 14-Mar-12 2:17am    
first of all thanks for giving reply

I mentioned that when am pasting the url in downloadlink in any browser it prompts a open/save dialog i dont want that i want that file to copy to localdrive directly in button click ..
if u dont mind, plz read the whole question what i posted
Dhaval__Patel 14-Mar-12 4:59am    
hey..
i have tried following code but it simply copied file from url to my machine location... its not prompting any open save dialog...

protected void Button1_Click(object sender, EventArgs e)
{
string remoteUri = "http://i.technet.microsoft.com/dynimg/";
string fileName = "IC626.gif", myStringWebResource = null;
WebClient myWebClient = new WebClient();
myStringWebResource = remoteUri + fileName;
myWebClient.DownloadFile(myStringWebResource, @"D:\"+fileName);
}

so i dont know what's going with u but its working great with me..
hitech_s 14-Mar-12 6:52am    
in your case we know the file what we going to download where as in my case i dont know which file is downloading because another method is calling which returns the original file that is going to be downloaded...

if you observe the URL what i had posted is this one :: "http://mydomain.com/view/download?uname=test&sid=123"
Dhaval__Patel 14-Mar-12 7:26am    
i have tried for all the file .. even though i have tried to copy gif file to text file .. it also worked..
hitech_s 14-Mar-12 7:57am    
with the above url am posted is not a file directly it calls another method download which in turn returns a file....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900