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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:02:06+00:00 2026-05-23T23:02:06+00:00

I have a stream writer that opens using a WebClient.OpenWrite call. For this simplified

  • 0

I have a stream writer that opens using a WebClient.OpenWrite call. For this simplified case, assume that reader is reading a multiple of dataChunkSize.

using (Stream writer = myWebClient.OpenWrite(myURIString)
{
    using (FileStream reader = new FileStream(myFileName, FileMode.Open, FileAccess.Read)
    {
        for(int i = 0; i < reader.Length; i += dataChunkSize)
        {
            byte[] data = new byte[dataChunkSize];
            reader.Read(data, 0, dataChunkSize);
            writer.Write(data, 0, dataChunkSize);
        }

        reader.Close();
        reader.Dispose();
    }

    writer.Close();
    writer.Dispose();
}

My data is the size of 2 dataChunkSizes. However, it does not send any data (no data is received) until the writer.Close() call is called, where it only sends the first dataChunkSize worth of data…the second dataChunkSize of data is never sent.

How can I get it to send after every Write call? I tried adding writer.Flush() but this did not help.

Thanks.

  • 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-23T23:02:06+00:00Added an answer on May 23, 2026 at 11:02 pm

    I think your issue is because your last chunk is perhaps not the full length you expect (dataChunkSize). Also, I would add Flush to force each write there and then if needed (thou I am not sure if the flush will work). Try changing you for loop contents to this…

    byte[] data = new byte[dataChunkSize];
    int bytesRead = reader.Read(data, 0, dataChunkSize);
    writer.Write(data, 0, bytesRead);
    writer.Flush();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one method that receives a Stream to write on it using a
This is my current code: public void WriteXml(System.Xml.XmlWriter writer) { CloseConnection(); using (Stream source
I have a stream that is reading the response from a site. I am
I have a library that handles reading and writing a cache file. This library
I have this piece of code in c#: private static void _constructRow(SqlDataReader reader, system.IO.StreamWriter
I have response stream from a ftp web request that returns binary file. I
I have a stream of data that I want to place into a container.
I have a .Net application that needs to run several executables. I'm using the
I'm using C# and i have written a locally installed application that dynamically generates
I have a Web Handler that I'm using to read a file and then

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.