4

With this code I can download the file but I should know the file name. Is there any way to download whatever file at the directory (Directory link: https://www.dropbox.com/sh/koao8dlfpcao8sk/XzDZMfejiF) and run it?

private void Update_Load(object sender, EventArgs e)
{
        WebClient webClient = new WebClient();
        webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
        webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
        webClient.DownloadFileAsync(new Uri("https://www.dropbox.com/s/6o5kvzr7s0c6mne/Test.txt"), @"C:\Users\Admin\Downloads\Test.txt");
}
Tudor
  • 61,523
  • 12
  • 102
  • 142
a1204773
  • 6,923
  • 20
  • 64
  • 94

3 Answers3

4

Dropbox has a REST API, so you just need to do an HTTP GET on the appropriate URL to get the folder's content. Look at /metadata in the dropbox API reference. That'll give you the contents of the folder if you pass list=true, and you can parse the response to get the filename. Then you can download the file.

MNGwinn
  • 2,394
  • 17
  • 18
0

You seem to already have the downloading part covered. Assuming this is a Windows EXE that you're downloading, after it's downloaded you can run it using Process.Start.

Edit: This question seems to provide some ideas of how to do this. Basically you make an HttpWebRequest using the directory URL you have, and then you have to parse what's returned here in order to get a list of the files contained in that directory (which may just be a single file). Once you have that, you can download that file in the normal way.

Community
  • 1
  • 1
MusiGenesis
  • 74,184
  • 40
  • 190
  • 334
  • I can download with this way but I must know file name to download... I need a way to download whatever file in directory (I don't know file name) and then run that file (but I dont know the file name) to use Process.Start. I just will know the save directory – a1204773 Jun 19 '12 at 13:40
0

When you start the download via DownloadFileAsync you need to specify a file name anyway. Just use that name and pass it to Process.Start as MusiGenesis suggested.

Ventsyslav Raikov
  • 6,882
  • 1
  • 25
  • 28
  • Yes I know that... I showed that code to show that I know how to download a single file and wanted you to suggest me by modifying this code or just any other to download unknown file from a directory and run it – a1204773 Jun 19 '12 at 13:52
  • how can you download unknown file? you need to have the uri and decide on a local file name - that's it. Then just call Process.Start with the local file name. – Ventsyslav Raikov Jun 19 '12 at 13:54