im having the same issue the line breaks still in the document y try the code thanks for the help, the issue start with a format document or a simple document that contains some "intros" by the text, in word i use a simple replace using "^p" then search and replace with a space, this merge me all the document in one paragraph, im still looking for a method because im trying to build a document by giving by parameter another document.
Fdsgfsdgfsdgfsd degwegweg tewtgewt
Wetgewgtwe
Wetewtewtew
Wertwetwe
awetewta
giving a word document with the quote info then i run the code and i get this
Fdsgfsdgfsdgfsd degwegweg tewtgewt
Wetgewgtwe
Wetewtewtew
Wertwetwe
awetewta
but the line breaks still in the document this is the code i use
- Code: Select all
Document doc = new Document(FileUpload1.PostedFile.FileName.ToString());
foreach (Section sec in doc.Sections)
{
foreach (Paragraph par in sec.Paragraphs)
{
for (int i = 0; i < par.ChildObjects.Count; i++)
{
if (par.ChildObjects[i].DocumentObjectType == DocumentObjectType.Break)
{
Break Pbreak = par.ChildObjects[i] as Break;
if (Pbreak.BreakType == BreakType.LineBreak)
{
par.ChildObjects.Remove(Pbreak);
}
}
}
}
for (int j = 0; j < sec.Body.ChildObjects.Count; j++)
{
if (string.IsNullOrWhiteSpace((sec.Body.ChildObjects[j] as Paragraph).Text.Trim()))
{
sec.Body.ChildObjects.Remove(sec.Body.ChildObjects[j]);
j--;
}
}
}