ItsMods

Full Version: How to download a file in C++
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey OMA s,
today I'm going to show you how to download a file in C++.

You're going to open VC++, press New project and choose Windows Forms Application.

Make some GUI and go to your code.
[Image: YamSG0iPrp.png]

Double click the button to add some code and scroll up till the beginning of your header.

Include <windows.h> like this.
[Image: yxJXmxGxo8.png]

Scroll down a bit and add using namespace System::Net; right here,
[Image: XnkwmJaVFH.png]

Scroll down a bit more and add WebClient(); here..
[Image: O1iQvC4M8H.png]

Now you're done with including the libraries and initializing stuff. Let's add a download code to our button!

C++ Code
  1. private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
  2.  
  3. try
  4. {
  5. WebClient^ downloadclient = gcnew WebClient;
  6. MessageBox::Show("Starting download..");
  7. downloadclient->DownloadFile("http://www.mysite.com/mystuff/myapp.exe","myapp.exe");
  8. MessageBox::Show("Download finished!");
  9.  
  10. }
  11. catch ( WebException^ webEx )
  12. {
  13. MessageBox::Show("Download failed!");
  14.  
  15. }
  16. }


And you're basically done! Replace the DownloadFile("http://www.mysite.com/mystuff/myapp.exe","myapp.exe");
with your link and name of the file, and watch how it downloads!

Press that [Image: postbit_reputation.gif] button for more tutorials!

[Image: O1iQvC4M8H.png]
It hurts me when people fuck up spaces/tabs like that..
hahha yes the same @Pozzuh , hmmm seems like in C++ instead the point it puts :: , in C# is point, arrg im confused
The same for Java please !