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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:52:29+00:00 2026-06-18T11:52:29+00:00

I am trying to download some text output from the screen as a text

  • 0

I am trying to download some text output from the screen as a text file. Following is the code. It’s working on some pages and not working at all on other pages. Can anyone please suggest what’s wrong here?

protected void Button18_Click(object sender, EventArgs e){
    Response.Clear();
    Response.Buffer = true;
    Response.ContentType = "text/plain";
    Response.AppendHeader("content-disposition", "attachment;filename=output.txt");

    StringBuilder sb = new StringBuilder();
    string output = "Output";
    sb.Append(output);
    sb.Append("\r\n");
    Response.Write(sb.ToString());
}
  • 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-18T11:52:30+00:00Added an answer on June 18, 2026 at 11:52 am

    As already mentioned by Joshua, you need to write the text to the output stream (using Response object). Also, don’t forget to invoke Response.End() after that.

    protected void Button18_Click(object sender, EventArgs e)
    {
        StringBuilder sb = new StringBuilder();
        string output = "Output";
        sb.Append(output);
        sb.Append("\r\n");
        
        string text = sb.ToString();
        
        Response.Clear();
        Response.ClearHeaders();
    
        Response.AppendHeader("Content-Length", text.Length.ToString());
        Response.ContentType = "text/plain";
        Response.AppendHeader("Content-Disposition", "attachment;filename=\"output.txt\"");
    
        Response.Write(text);
        Response.End();
    }
    

    Edit 1: added more details

    Edit 2: I was reading other SO posts where users were recommending to put quotes around the filename:

    Response.AppendHeader("content-disposition", "attachment;filename=\"output.txt\"");
    

    Source:
    https://stackoverflow.com/a/12001019/558486

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

Sidebar

Related Questions

I am trying to download some image file from Google Drive using the python
All I need to do is download some basic text-based and image files from
Possible Duplicate: How to download a text file or some objects from webpage using
I am trying to do download some images from server then , set these
I am trying to download a file from a website using python and mechanize.
I'm trying to download the XLS file from this page: http://www.nordpoolspot.com/Market-data1/Elspot/Area-Prices/ALL1/Hourly/ (click on Export
Greetings, I'm trying to download a web page with the following code: public partial
I'm trying to assemble a CSV file from some DB data and send it
i'm trying to create a page where users can download some .log file. this
I'm trying to download some data using pure javascript/html from cross-domain, dropbox to be

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.