Download-Dateien mit C# - Windows Forms-und webclient

Ich bin, zu lernen, wie die Verwendung von http-Anfragen und-webclient in der C# - windows forms. Derzeit habe ich bekommen den folgenden code aus Beispiel und ich versuche es so gut funktioniert wie es verstehe.

Den code erfolgreich ausgeführt wird und zeigt die Meldung "Download Complete" - box, aber es nicht tatsächlich die Datei herunterzuladen. Würde mir jemand erklären wie das funktioniert und was ich falsch mache?

    private void btnDownload_Click(object sender, EventArgs e)
    {
        string filepath = txtBxSaveTo.Text.ToString();
        WebClient webClient = new WebClient();
        webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
        webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
        webClient.DownloadFileAsync(new Uri("http://download.thinkbroadband.com/10MB.zip"), filepath);
    }

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

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

    private void btnSavetoLocation_Click(object sender, EventArgs e)
    {
        FolderBrowserDialog selectedFolder = new FolderBrowserDialog();

        if (selectedFolder.ShowDialog() == DialogResult.OK)
        {
            txtBxSaveTo.Text = selectedFolder.SelectedPath;

        }
    }
}

}

InformationsquelleAutor Kevin Farris | 2015-05-12
Schreibe einen Kommentar