Downloading Error With Files over 1.0GB

Ben

Hello I'm trying to make a program that can download a file problem is when it downloads a file that is over 1GB it Crashes and breaks is there a way to make it so it can download files that are way bigger Here is the code I'm using

private void button1_Click(object sender, EventArgs e)
{
    WebClient web = new WebClient();
    string listbox = listBox1.SelectedItem.ToString();

    web.DownloadFileAsync(new Uri(http://example.com/file.avi), location" + "file.avi");
    web.DownloadProgressChanged += new DownloadProgressChangedEventHandler(web_DownloadProgressChanged);
    web.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
}

private void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
    // Place for a message when the downloading has compleated
}             

void web_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
    int bytesin = int.Parse(e.BytesReceived.ToString());
    int totalbytes = int.Parse(e.TotalBytesToReceive.ToString());
    int kb1 = bytesin / 1024;
    int kb2 = totalbytes / 1024;

    toolStripStatusLabel1.Text = kb1.ToString() + "KB out of " + kb2.ToString() + "KB (" + e.ProgressPercentage.ToString() + "%)";
    progressBar1.Value = e.ProgressPercentage;             
}
Camilo Terevinto

This

void web_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
    int bytesin = int.Parse(e.BytesReceived.ToString());
    int totalbytes = int.Parse(e.TotalBytesToReceive.ToString());
    int kb1 = bytesin / 1024;
    int kb2 = totalbytes / 1024;

    toolStripStatusLabel1.Text = kb1.ToString() + "KB out of " + kb2.ToString() + "KB (" + e.ProgressPercentage.ToString() + "%)";
    progressBar1.Value = e.ProgressPercentage;             
}

is causing your issue. You are converting a long to int and getting an OverflowException once BytesReceived or TotalBytesToReceive go above int32.MaxValue.

Change the method to something like this:

void web_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
    long kb1 = e.BytesReceived / 1024;
    long kb2 = e.TotalBytesToReceive / 1024;

    toolStripStatusLabel1.Text = kb1.ToString() + "KB out of " + kb2.ToString() + "KB (" + e.ProgressPercentage.ToString() + "%)";
    progressBar1.Value = e.ProgressPercentage;             
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Asynchronously and parallelly downloading files

From Dev

Downloading files in a SPA

From Dev

DownloadManager downloading files over 2.1 GB

From Dev

error downloading files in IE in Azure VM

From Dev

Selenium not fully downloading files

From Dev

Downloading .ttf files with Node

From Dev

Peculiar error downloading keys/files from S3 bucket - [Errno 1] Operation not permitted

From Dev

Downloading files outside the webroot

From Dev

Downloading files in Mojolicious

From Dev

Downloading files concurrently in Python

From Dev

Multiple dex files error when downloading my library from Sonatype

From Dev

WebClient Downloading Zip Files 404 error on redirect

From Dev

downloading files over the internet, if the component has been selected (WITH Inno Tools Downloader)

From Dev

Downloading files WKWebView ios

From Dev

Downloading files from URL

From Dev

BeautifulSoup not downloading files as expected

From Dev

When downloading a windows steam game over Ubuntu Wine, I get the error "content server unreachable"

From Dev

SSL error 1409442E downloading file over HTTPS with TIdHTTP

From Dev

Error while downloading HTTPS files using wget

From Dev

When downloading a windows steam game over Ubuntu Wine, I get the error "content server unreachable"

From Dev

Windows 7 x64 Out of Memory Error - With over 1GB still available

From Dev

Downloading over 1000 files in python

From Dev

Peculiar error downloading keys/files from S3 bucket - [Errno 1] Operation not permitted

From Dev

Transferring large (8 GB) files over ssh

From Dev

Why should I choose BitTorrent over HTTP when downloading large files?

From Dev

Error found when start downloading the binary files from kaa

From Dev

Failed network error while downloading the files from Google Chrome

From Dev

"File (code: 302): Error downloading file" in Scrapy Files Pipeline

From Dev

rentrez error HTTP failure: 400 when downloading >1/3 of records

Related Related

  1. 1

    Asynchronously and parallelly downloading files

  2. 2

    Downloading files in a SPA

  3. 3

    DownloadManager downloading files over 2.1 GB

  4. 4

    error downloading files in IE in Azure VM

  5. 5

    Selenium not fully downloading files

  6. 6

    Downloading .ttf files with Node

  7. 7

    Peculiar error downloading keys/files from S3 bucket - [Errno 1] Operation not permitted

  8. 8

    Downloading files outside the webroot

  9. 9

    Downloading files in Mojolicious

  10. 10

    Downloading files concurrently in Python

  11. 11

    Multiple dex files error when downloading my library from Sonatype

  12. 12

    WebClient Downloading Zip Files 404 error on redirect

  13. 13

    downloading files over the internet, if the component has been selected (WITH Inno Tools Downloader)

  14. 14

    Downloading files WKWebView ios

  15. 15

    Downloading files from URL

  16. 16

    BeautifulSoup not downloading files as expected

  17. 17

    When downloading a windows steam game over Ubuntu Wine, I get the error "content server unreachable"

  18. 18

    SSL error 1409442E downloading file over HTTPS with TIdHTTP

  19. 19

    Error while downloading HTTPS files using wget

  20. 20

    When downloading a windows steam game over Ubuntu Wine, I get the error "content server unreachable"

  21. 21

    Windows 7 x64 Out of Memory Error - With over 1GB still available

  22. 22

    Downloading over 1000 files in python

  23. 23

    Peculiar error downloading keys/files from S3 bucket - [Errno 1] Operation not permitted

  24. 24

    Transferring large (8 GB) files over ssh

  25. 25

    Why should I choose BitTorrent over HTTP when downloading large files?

  26. 26

    Error found when start downloading the binary files from kaa

  27. 27

    Failed network error while downloading the files from Google Chrome

  28. 28

    "File (code: 302): Error downloading file" in Scrapy Files Pipeline

  29. 29

    rentrez error HTTP failure: 400 when downloading >1/3 of records

HotTag

Archive