Jump to content
  • Advertisement
Sign in to follow this  
FreJa

downloading a file with c#

This topic is 3886 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm trying to use the WebClient.DownloadClient method to get a file from the web. However, my url for the file is of the type: http://somewebsite.com/download.htm?ID=20&username=myusername&pass=mypass . So, the url for the file is only given to me, after download.htm verifies all the arguments (ID, username and pass). After it does I get a zip file. My question is, how can I download this file in c#? Thank you

Share this post


Link to post
Share on other sites
Advertisement
Thanks, that problem is solved!

However, I have another problem: I want to save the file in my computer with the name it has on the server... How can I do it?

Thanks again

Share this post


Link to post
Share on other sites
The only way I could do it so far (a very poor way), is by checking the ContentType value of my HttpResponse... this is bad however, because, imagine I'm trying to download a zip file, the content type can vary according to the compression used...

Any more ideas?

Thanks again

Share this post


Link to post
Share on other sites
Depending on the implementation on the server you may receive a header called Content-Disposition which has two parts and should look like this:

"attachment; filename=somefilename"

The web client should contain this in its headers (see the Headers property or the headers property of your HttpResponse), but you will probably have to parse out the filename bit yourself.

If the response does not contain this header (it is an optional extension header I believe) you may have to fall back to parsing the file name from the original URL or simply generating an arbitrary name based on the Content-type.

Hope this helps.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!