-1

I have been trying to download a file and run it than C#, with limited success. Here's my script:

using (WebClient Client = new WebClient())
{
    Client.DownloadFile("http://vx.zapto.org/newscript/enone.jpg", ".jpeg");
    MessageBox.Show("Downloaded!");
}

Can anyone help?

user1797443
  • 236
  • 1
  • 5
  • 15

1 Answers1

11

Try this maybe (if by run it you meant open it with default application):

using (WebClient Client = new WebClient())
{
    FileInfo file = new FileInfo("filename.jpeg");
    Client.DownloadFile("http://vx.zapto.org/newscript/enone.jpg", file.FullName);
    MessageBox.Show("Downloaded!");

    Process.Start(file.FullName);
}

Note that the second parameter to WebClient.DownloadFile(..) is a filename, not an extension.

neeKo
  • 4,280
  • 23
  • 31
  • YES!!! Thank you so much it works perfectly! But would it be possible to save the file that was downloaded to a certain place? – user1797443 Dec 09 '12 at 00:44
  • @user1797443 Certainly - instead of `"filename.jpg"` specify your own location. Did you want a save file dialog? – neeKo Dec 09 '12 at 00:51