0

I'm writing because I'm stuck on a problem, I have code that currently writes the output of an aspx page to a word document. This code works perfectly fine. However I need to actually save that file to the server. Here is the code that is working:

HttpContext.Current.Response.ContentType = "application/msword";
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=IR-" + lblReportNumber.Text + ".doc");
HttpContext.Current.Response.Write(this.Page.ToString());

Here is what I have tried to do to get the desired results

string fileName = Path.Combine(Server.MapPath("~/"), "IR-" + lblReportNumber.Text + ".doc");
string page = this.Page.ToString();

The problem is, the .doc file that's written to the server only contains the page name for text and not the full contexts of the html.

So if I open the word document from my second set of code all I see is "clientpage.aspx" however the first block of code opens the fully formatted word doc.

Does anyone have any ideas?

Renjith
  • 5,783
  • 9
  • 31
  • 42
Joe Stellato
  • 558
  • 9
  • 31
  • Your first code doesn't actually do anything. It only works because ASP.Net is writing the rest of the page to the response anyway. – SLaks Jun 19 '13 at 03:28

1 Answers1

-1

You need to actually write to the file using StreamWriter

like

    using (System.IO.StreamWriter file = new System.IO.StreamWriter("filename")
    {
           file.WriteLine()
    }

See here: http://msdn.microsoft.com/en-us/library/vstudio/8bh11f1k.aspx

iefpw
  • 6,816
  • 15
  • 55
  • 79
  • Thanks, this is something new to me, so I'm not really clear how to implement it. How do I pass the entire page to the streamwriter? – Joe Stellato Jun 19 '13 at 12:36