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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:29:19+00:00 2026-05-25T00:29:19+00:00

I want to create a Text file in my code behind file in my

  • 0

I want to create a Text file in my code behind file in my web application. However, I am not allowed to save this file to server. So I tried to use MemoryStream class to save my file into memory. So far I have,

MemoryStream memoryStream = new MemoryStream();
TextWriter textWriter     = new StreamWriter(memoryStream);
textWriter.WriteLine("Something");
memoryStream.Close();

It seems like working but my requirement is to open this file on client browser when he/she clicks button. Since this file does not have a physical path like …./text.txt. I have no idea how to open it on browser.

How can I do this in ASP.Net using C#. I searched a lot but could not find a solution working for me.

Thanks in advance.

  • 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-25T00:29:20+00:00Added an answer on May 25, 2026 at 12:29 am

    This is a lot easier than you think. Keep in mind that the HTTP protocol doesn’t actually transfer “files” in the strictest sense of the word. It transfers requests and responses, each containing headers and content. In this case, you’re concerned with the headers and content of the response.

    The easiest way to do this in a WebForms application is with a generic handler. Specifically, take a look at the implementation of the handler’s response in that link:

    context.Response.ContentType = "image/png";
    context.Response.WriteFile("~/Flower1.png");
    

    This is writing the content of an image file to the response after setting the response’s header appropriately. What you want is closer to what’s commented out in the implementation:

    context.Response.ContentType = "text/plain";
    context.Response.Write("Hello World");
    

    This would send to the browser plain text, nothing more. The browser won’t think it’s a web page or anything like that, won’t apply any styles to it, etc. As far as the web browser is concerned, it just downloaded a text file with the words “Hello World” in it. You can Response.Write() all the text you want to build that file.

    You can further customize your response headers to give the browser even more information. For example, if you add the following header to your HttpResponse:

    Content-Disposition: attachment; filename=myfile.txt
    

    Then the browser will translate that to mean that this “file” should be downloaded and saved, not just displayed. (Of course, the user’s browser settings may tell it to display it anyway, but this is the proper way for the server to “suggest” to the browser that it should save the file.)

    From the point of view of the browser, it doesn’t matter where the “file” came from. Whether it was from the server’s file system or dynamically generated or magically conjured, it makes no difference. The browser is concerned only with the response headers and content. If the headers say it’s text, and they say that it’s a file, then the content will be treated as a text file.

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

Sidebar

Related Questions

I want to create a simple C# application that uploads a text file to
I want to be able to create a temporary text File in Java to
this table i want to create job_id dynamic Jobs Title text Job Description text
I have a problem with my code. I want to create a XML file
I have a text ( .txt ) file that contains Java code! I want
I want to create a text file into that folder that I am creating
So I create text(php) editor and I want to execute PHP code without refreshing
Using C#, I want to create an MD5 hash of a text file. How
I'm trying to create a text file in my Windows Forms application. It is
I want to pre-append some text a a CSV file that is created by

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.