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 8663461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:59:24+00:00 2026-06-12T16:59:24+00:00

I am trying to write all bytes downloaded into 3 different files, Now, I

  • 0

I am trying to write all bytes downloaded into 3 different files, Now, I am using WebRequest and WebResponse Objects. I am sure its the correct way to go?
I got stuck in part of writing data to files in parts.No matter what data is written,objective right now is to read data from same stream and write it to 3 different files.
I can write to the first file successfully, than it gives error–stream is not readable when I try to assign the stream(which I got from response.getResponseStream()) to another binaryreader.

I have tried it two ways-one is to directly pass responsestream to different binaryreaders,failed.
Secondly I tried to create separte references for each binaryreader,that failed too.
Here is the code if it can help:-

using (Stream strm = res.GetResponseStream())
{
    using (Stream strm1 = strm)
    {
        int i = 0;
        BinaryReader br = new BinaryReader(strm1);
        br.BaseStream.BeginRead(buffer, 0, buffer.Length, 
            new AsyncCallback(ProcessDnsInformation), br);
        Console.WriteLine("Data read {0} times", i++);
        Console.ReadKey();
        File.WriteAllBytes(@"C:\Users\Vishal Sheokand\Desktop\Vish.bin", buffer);
        br.Close();
    }

    using (Stream strm2=strm)
    {
        int i = 0;
        BinaryReader br = new BinaryReader(strm2);
        br.BaseStream.BeginRead(buffer, 0, buffer.Length, 
            new AsyncCallback(ProcessDnsInformation), br);
        Console.WriteLine("Data read {0} times", i++);
        Console.ReadKey();
        File.WriteAllBytes(@"C:\Users\Vishal Sheokand\Desktop\Vish1.bin", buffer);
        br.Close();
    }

    using (Stream strm3 = strm)
    {
        int i = 0;
        BinaryReader br = new BinaryReader(strm3);
        br.BaseStream.BeginRead(buffer, 0, buffer.Length, 
            new AsyncCallback(ProcessDnsInformation), br);
        Console.WriteLine("Data read {0} times", i++);
        File.WriteAllBytes(@"C:\Users\Vishal Sheokand\Desktop\Vish2.bin", buffer);
        br.Close();
    }
}

I am learning C#, please ignore some(or all of) stupid coding.

  • 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-12T16:59:26+00:00Added an answer on June 12, 2026 at 4:59 pm

    You have at least two problems. First, look at this:

    using (Stream strm = res.GetResponseStream())
    {
        using (Stream strm1 = strm)
        {
            ...
        }
    

    As soon as you’ve exited the inner block, the stream will be disposed – so you can’t read from it in the next block.

    Secondly, you’re calling BeginRead which is going to start reading data – but then you’ve completely decoupled the timing of the callback from when you decide to write all the data. I would strongly advise you to get all this working with synchronous IO first, then move onto asynchronous IO if appropriate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a library to separate all the disk activity out into
Hi all I am trying to write a script which recursively searches directories from
I'm trying to write a method that removes all non alphabetic characters from a
I'm trying to write some code to catch all Errors and ErrorEvents however i
I was trying to write a function to get all subsequences of a list
I'm trying to write a macro to delete all rows that have True in
I'm trying to write a function that makes all the windows in an Emacs
I'm trying to write a Photoshop script that will show all layers of a
I'm trying to write a method that will compute all permutations of a power
I'm trying to write a command for mplayer that will play all the music

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.