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

  • SEARCH
  • Home
  • 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 7037147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:30:33+00:00 2026-05-28T01:30:33+00:00

I was trying to test a resumable download using c#. I found that add

  • 0

I was trying to test a resumable download using c#. I found that add range will help by looking at some blogs. But in the following code add range have no meaning.
Guys Suggest me how to solve the issue.
What method will be effective to make a Resumable download??

HttpWebRequest myrequest = null;
    HttpWebResponse myresponse = null;
    private int interval=2048;
    public bool set_url(string todonwloads,string tosaves)
    {
        this.todownload = todonwloads;
        this.tosave = tosaves;
        return true;
    }
    public bool start_download()
    {
        myrequest = (HttpWebRequest)WebRequest.Create(this.todownload);
       // it the following code. 
       //If i dont write addrange. It will download same portion of the file.
        myrequest.AddRange(4000,8000);

        try
        {
            myresponse = (HttpWebResponse)myrequest.GetResponse();
            if (myresponse.StatusCode == HttpStatusCode.OK)
            {
                Stream ReceiveSteam = myresponse.GetResponseStream();
                FileStream fs = new FileStream(
                                        this.tosave, 
                                        FileMode.Create, 
                                        FileAccess.Write, 
                                        FileShare.None);
                int reads;
                byte[] buffer = new byte[this.interval];
                while ((reads = ReceiveSteam.Read(
                                         buffer, 
                                         0, 
                                         this.interval)) > 0)
                {
                    fs.Write(buffer, 0, reads);
                }
                return true;
            }


        }
        catch (WebException ex)
        {

            throw ex;
        }
        finally
        {
            if (myresponse != null)
            {
                myresponse.Close();
            }
        }
        return false;

    }
  • 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-05-28T01:30:34+00:00Added an answer on May 28, 2026 at 1:30 am

    You currently create and overwrite the file every time you download a section of the file:

    //            Overwrites the file each time -\/
    ... = new FileStream(this.tosave, FileMode.Create, ...
    

    You instead need to open or create the file using FileMode.OpenOrCreate, then seek to the last section of the file you wrote to:

    // seek to the last end offset, you'll need to save this somehow
    fs.Seek(lastOffset, SeekOrigin.Begin);
    
    int reads;
    byte[] buffer = new byte[this.interval];
    while ((reads = ReceiveSteam.Read(buffer, 0, this.interval)) > 0)
    {
        fs.Write(buffer, 0, reads);
        lastOffset += reads;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying to test an AccountController that uses DotNetOpenAuth but I am running into
When trying to test the speed of functions, I found that not all parts
I'm trying to test some application logic that is dependent on the Values property
I'm trying to test web service calls using an ASP.NET page that creates a
just trying to test for equality in this piece of code, but getting a
Im trying to test my successfully creates a new user after login (using authlogic).
I am trying to test the likelihood that a particular clustering of data has
I am trying to test that a particular method throws an expected exception from
I am trying to test a class that manages data access in the database
I am trying to test a proof of concept that I can run a

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.