Click here to Skip to main content
15,918,275 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am generating word header/footer into a word document using the following code: The header/footer is being generated properly but is also duplicated as the first text in the document. I am looking for a way to programmitically not duplicate or to remove the duplicate text in the word document.

Response.ContentType = "application/msword"
Response.AppendHeader("Content-Disposition", "attachment;filename=mytest.doc")%>

Response.Write("" + "" + "<title>Dynamic Generated Document")

Response.Write("")

Response.Write(" @page" + "{size:8.5in 11.0in; mso-footer: f1; mso-header: h1; padding:24.0pt 24.0pt 24.0pt 24.0pt;" + " margin:0.75in 0.50in 0.75in 0.50in ; " + " mso-header-margin:.5in; " + " mso-footer-margin:.5in; mso-paper-source:0;}" + " div.Section1" + " {page:Section1;}" + "p.MsoFooter, li.MsoFooter, div.MsoFooter{margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; tab-stops:center 3.0in right 6.0in; font-size:12.0pt; font-family:'Arial';}")

Response.Write("{margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; tab-stops:center 3.0in right 6.0in; font-size:12.0pt; font-family:'Arial';}" + "-->" + "" + "")
Response.Write("
")

Response.Write("
")

Response.Write("MY HEADER" & "
")

Response.Write("
")
Response.Write("MY FOOTER" &
")

Response.Write("
")
Posted
Updated 3-Mar-10 8:19am
v3

I would suggest creating a document in Word that looks the way you want it to, saving it as a docx, then comparing the XML to see where yours is wrong.
 
Share this answer
 
Thanks, I created a word doc with a header and footer, how do I view the xml?
 
Share this answer
 
v2
If you change the extension from .docx to .zip, you will find the file is just a zip. When you open it, the xml is inside.
 
Share this answer
 
Thanks, I did see the xml and that was definitely worth a try. However when I copy the xml into the code file it creates the word document but does not create the header and footer. It is a very strange problem, the only code that seems to actually create a word header/footer is what I included in the original post. I have played with it a great deal by removing certain parts so I think I have it down to a minimum I just can't get it to create the header/footer and not duplicate the text from the header/footer in the body of the document.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900