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
ASP.NET

Avatar of undefined
Last Comment
kdunnett

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
dfu23

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
REA_ANDREW

how about

Environment.NewLine?
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
nauman_ahmed

try

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

or

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

--Nauman.
Your help has saved me hundreds of hours of internet surfing.
fblack61
kdunnett

ASKER
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