Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8287125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:57:02+00:00 2026-06-08T11:57:02+00:00

This is my C# code to download a ZIP file from my server. When

  • 0

This is my C# code to download a ZIP file from my server. When I download I don’t receive the file, but it is partially downloaded.

public static void Download(String strURLFileandPath, String strFileSaveFileandPath)
{
    HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(strURLFileandPath);
    HttpWebResponse ws = (HttpWebResponse)wr.GetResponse();
    Stream str = ws.GetResponseStream();
    byte[] inBuf = new byte[100000];
    int bytesToRead = (int)inBuf.Length;
    int bytesRead = 0;
    while (bytesToRead > 0)
    {
        int n = str.Read(inBuf, bytesRead, bytesToRead);
        if (n == 0)
            break;
        bytesRead += n;
        bytesToRead -= n;
    }
    try
    {

        FileStream fstr = new FileStream(strFileSaveFileandPath, FileMode.OpenOrCreate, FileAccess.Write);
        fstr.Write(inBuf, 0, bytesRead);
        str.Close();
        fstr.Close();
    }
    catch (Exception e) {
        MessageBox.Show(e.Message);
    }
}

I thing the problem is happening here

byte[] inBuf = new byte[100000];

When I increase the value of byte[] inBuf = new byte[100000]; to byte[] inBuf = new byte[10000000];

The file is downloading perfectly.

But my problem is if I download files larger than 50 MB (eg.: 200 MB) .

This method is not good.

Can anyone tell me how can I fix this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:57:03+00:00Added an answer on June 8, 2026 at 11:57 am

    You could copy directly from stream to stream using the Stream.CopyTo() method.

    Or even simpler: Use the WebClient class and its DownloadFile method to download the file. This solution would replace your complete method:

    var client = new WebClient();
    client.DownloadFile(strURLFileandPath, strFileSaveFileandPath);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to download a large .zip file from a web server but I
I have this code to download a file, but on sourceforge.net sever there is
With this code I can download the file but I should know the file
Here I implemented code for file download from server. its working fine. Now I
I am using this code to download a package from server A and put
I am trying to download a .zip file from a FTP server and I
I'm referring following code to download a file from particular URL. public class FileFromServerExample
I'm trying to make android download a zip file from my web server using
I want to download a large size zip file from a server. To do
I start a download using PHP with this code: <? $_REQUEST['file'] = urldecode($_GET['file']); header(Content-type:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.