Question download attachment php file with downloadfileasync

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
How do you download an attachment php file with downloadfileasync which u need the actual file url? Right now i am just using Process.start
 
There's no "attachment" there. It's just the output of a script, exactly like ASP.NET. You should find that DownloadStringAsync will work for text output and DownloadDataAsync will work for binary output. You'll get the result as either a String or Byte array, which you can then write to a file if required using the File.WriteAllText or .WriteAllBytes method.
 
oh it actually downloaded the login page and want me to login again cause i was using downloadfile. guess i need to use webbrowser to download it or something
 
No, you don't need to use a WebBrowser. If you need to perform a multi-step operation that requires a session then you you'll need to use the HttpWebRequest and HttpWebResponse classes, which allow you to use the cookies from one response with the next request. You could also inherit the WebClient and add that functionality if you might need to reuse it because the WebClient uses those request and response classes internally.
 
Ok when i navigate the browser to that page, it popup a download dialogbox. could i have it auto download it to a directory without popping the box?
 
I have tried that and i got a 417 error on the .getresponse(). Thats why i went to the webbrowser. Tried setting ServicePointManager.Expect100Continue = False and when that doesnt work. i really dont know what to do.
 
ok i used internetgetcookieex and got the cookie from the browser instead... now i just need to figure out how to download the file with webrequest.
 
Last edited:
I think the file downloaded ok. seems so much easier to download an image file with this. having a do loop to read the file from the stream
 
Back
Top