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.

preguntado el 24 de agosto de 12 a las 01:08

1 Respuestas

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)

Respondido 24 ago 12, 01:08

Ahh, thanks, it's always those little things that get me :P I'll accept in 5 minutes when it lets me :) - DannyF247

@exacerbatedexpert, I've used ... as just that - tripe-dot as replacement for "something not too important". - Alexéi Levenkov

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.