DannyF247
DannyF247

Reputation: 638

WebClient isn't downloading file, but returns Completed

My code is below. I'm trying to download a file, and my application gives me "filename Not Found - downloading" followed by "Finished" as a result of this code, but when I go and look no file has actually been downloaded.

    private void Form1_Load(object sender, EventArgs e)
    {
        download(@"mp3spi.jar", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\bin\lob\");
    }

    public void download(String filename, String path)
    {
        filenameLabel.Text = filename;
        MessageBox.Show(filename + " Not found - downloading.");
        WebClient webClient = new WebClient();
        webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
        webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
        webClient.DownloadFileAsync(new Uri("http://mysite.com/client/" + filename), path);
    }

    public void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
        progressBar1.Value = e.ProgressPercentage;
    }

    private void Completed(object sender, AsyncCompletedEventArgs e)
    {
        MessageBox.Show("Finished.");
    }

Can someone point me out what's wrong? I've thought maybe it needed to be ran as Administrator, but that just did the same exact thing.

Upvotes: 1

Views: 1825

Answers (1)

Alexei Levenkov
Alexei Levenkov

Reputation: 100547

Your code tries to save to folder path ("...\lob\") which is not file name like (...\lob\my_file.ext").

WebClient.DownloadFileAsync(Uri Uri address, string fileName)

Upvotes: 2

Related Questions