0

I'm using Server.Transfer and in the 2nd place I have a number of labels that are updated with a Request.Form["textbox_text"];

This all works really well, but the problem is I also want to write the content in that textbox to file like a word document using this method

Response.Clear();

Response.AddHeader("Content-disposition", "attachment; filename=Word.doc");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application / vnd.ms -word";
Response.ContentEncoding = System.Text.Encoding.Unicode;
Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());

StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);

htw.Write("<table><h2><b>[ Text ]</b></h2><br>" + TextBox_name.Text + "</table>");

Response.Write(sw.ToString());
Response.End();

But whenever I check the file it will not have anything written on it. I've even tried to save the value of a Request.Form to a static variable and then write that variable but without any success.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • I have created a web forms site and implemented it exactly as you did, and the document downloads just fine. Can you please give more details as: 1. When opened with a standard text editor (Open With: Notepad) what are the contents of the file? 2. Can you please see the Network tab in the browser's developer tools (F12) and see what is downloaded there? Do you get a HTTP 200 OK, or some error message? – Oguz Ozgul Mar 16 '20 at 20:42

1 Answers1

0

How are you using Server.Transfer()? Post that code, make sure you are using the overload that preserves the form values:

Server.Transfer("page.aspx", true);
mxmissile
  • 11,464
  • 3
  • 53
  • 79