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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:50:38+00:00 2026-06-18T05:50:38+00:00

I tried to write a text file using OutputStream.Write but, I’ve noticed that the

  • 0

I tried to write a text file using OutputStream.Write but, I’ve noticed that the last character of the file is not being sent.

Whether the file is 6KB or 242KB, the last character is skipped.

AwAIB0UfFlJTSTNABEQWGgMVAhNFBkVeKgVTSx4LCVQMBUUQRUMwBVFTGwcAEAASRRNTBipNQQMFDREYB
BUAH0VIKgVLRVccCRFFGRcbR08wREgDEQENEUkCDRNOTX5cS1ZXHgQGHFYIB0NOfgUIAwMABFQABBcdUg
YpRFcDHgZBAA0TRTEDBj1KQEZXREEdRRIKHFQGK0tARgUbFRULEkUFSF9+R1FXVxwJEUUkAAFQSTBWQQ0
xBBQHDV5MUkFIOgV2RgQYDhoWE0sxTEktQAwKVx8AB0UCDRcAQyxXS1FZSBUcBAIWUldDN1dAAxEHE1QI
E0UTTkJ+TARAFgYVVBAYARdSVSpESkdXAAAcBFg=

Note: whole text is one line in the text file.

My text file is somewhat similar to the above. So can anyone help me out?

My code:

var path = Request.QueryString["path"];
path = Server.MapPath(Url.Content("~/Files/" + path + "/somefile.txt"));
Response.Buffer = false;
Response.ContentType = "text/plain";
FileInfo file = new FileInfo(path);
int len = (int)file.Length, bytes;
Response.AppendHeader("content-length", len.ToString());
byte[] buffer = new byte[1024];
Stream outStream = Response.OutputStream;
using (Stream stream = System.IO.File.OpenRead(path))
{
    while (len > 0 && (bytes = stream.Read(buffer, 0, buffer.Length)) > 0)
    {
        outStream.Write(buffer, 0, bytes);
        len -= bytes;
    }
}
Response.Flush();
Response.Close();

UPDATE 1:
Now shows the complete text from the file.

UPDATE 2 :
Updated the complete C# code.

UPDATE 3:
Thanks, my friends, for all your efforts! I somehow made it work – the problem was Response.Flush() and Response.Close(); once I removed these 2 statements it started working. I don’t understand why this problem occurred as I always use Response.Flush() and Response.Close(). I never received this kind of error but this was the first time. If anyone could give me an explanation, it would be appreciated. I will mark @AlexeiLevenkov’s post as the answer, as I just tested it again without the Response.Flush and Close() and it is working.

  • 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-18T05:50:39+00:00Added an answer on June 18, 2026 at 5:50 am

    Stream.CopyTo is easier approaach (as long as you can use .Net 4.0).

    using (var stream = System.IO.File.OpenRead(path))
    {
      stream.CopyTo(outStream);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to create a text file and write data to it using the
I want to write a backslash character to a text file using LaTeX. The
So, that's it. How can I write to a text file using AppleScript? I've
I tried to write a program that uses threads, but couldn't understand the o/p.
I tried to write a Taylor series expansion for exp(x)/sin(x) using fortran, but when
I have a text file that is formatted like JSON, but in a print/view
Does anyone know how to write to a text file in Android using a
I'm trying to write to a text file on my web server using HttpURLConnection.getOutputStream().
OK trying to write a SQL query to a text file. I have tried
I'm trying to write an array (list?) to a text file using Python 3.

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.