Link to home
Start Free TrialLog in
Avatar of kdunnett
kdunnett

asked on

Creating Word document with HttpContext but need page breaks

Good day all,

I have some code where I create a word document from some data on a page.  This is working great.  But I need to know how to call a page break for Word in HTML.

I'm calling the page in c# codebehind with asp.net off a click event of a button:
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset ="";
HttpContext.Current.Response.ContentType ="application/msword";
string strFileName = "GenerateDocument"+ ".doc";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + strFileName);

strHTMLContent.Append("<br>".ToString());
strHTMLContent.Append("<table align='Center'>".ToString());
...

Any ideas?
Kris
ASKER CERTIFIED SOLUTION
Avatar of dfu23
dfu23

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
how about

Environment.NewLine?
Avatar of kdunnett
kdunnett

ASKER

dfu23:
i can get page breaks on the html, but that doen't transfer to Word when I open the document

rea_andrew:
no luck with that
try

strHTMLContent.Append("<br>&nbsp;".ToString());

or

strHTMLContent.Append("\r\n\r\n".ToString());

--Nauman.
All,

I played around with what dfu23's comment, and I got it:

strHTMLContent.Append("<br clear=all style='page-break-before:always'>".ToString());

Only catch is that it has to be outside of the <table> tags and had to be part of a tag itself (like a <br> or <table>).  That was my mistake, as I was trying to put each <tr> on a separate page and it wasn't working.  Just did a complete table per page and volia.

All points to dfu23 as it got me here!
Kris