derp_in_mouth
derp_in_mouth

Reputation: 2183

Windows Phone 7 - How to download a file with progress?

How would I download a large file in Windows Phone 7 with a progress bar?

Upvotes: 3

Views: 1656

Answers (2)

msbg
msbg

Reputation: 4962

While Claus's answer would work, a potentially easier solution would be to use a web client. It would look something like this:

    ...
    WebClient wb = new WebClient();
    wb.DownloadProgressChanged += wbchange;
    ...

    private void wbchange(object sender, DownloadProgressChangedEventArgs e)
    {
        progressBar2.Value = e.BytesReceived;
        progressBar2.Maximum = e.TotalBytesToReceive;

        int val = (int)(e.BytesReceived / 1048576);
        int max = (int)(e.TotalBytesToReceive / 1048576);

        textBlock4.Text = val + "MB out of " + max.ToString() + "MB";
    }

This code would show a progress bar with the progress and a text block with the progress in MB.

Upvotes: 8

Related Questions