This project has moved and is read-only. For the latest updates, please go here.

Reading text from docx file ignores line breaks

May 10, 2012 at 3:08 PM
Edited May 10, 2012 at 3:15 PM

Hi, I am trying to read the text from a docx file and display it on a webpage by replacing the line breaks in the document with HTML Line Breaks namely "<br />".

Can this be done?

Here is what IvVe tried without success:

DocX document2 = DocX.Load("c:\\myworddocument.docx"); 
lblRes.Text = document2.Text.ToString().Replace(Environment.NewLine,"<br />");

If anyone can shed some light on this I would really appreciate it.


May 11, 2012 at 11:12 AM
No because these are not simple text documents. Line breaks as in \n are not contained within DocX documents.
Documents can have PageBreaks, SectionBreaks, Padding, LineSpacing. You cannot simply replace these with .Replace()