We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Question with the the api “Range.Replace(String, String, FindReplaceOptions) Method”

I hava a question with the the api “Range.Replace(String, String, FindReplaceOptions) Method”.
I want to replace or delete the first section break of the word file and keep the format unchanged.

My source word file look like this:
sourcePreview.png (6.8 KB)

I use the Aspose.word(Version 16.7) to replace the first section break to paragram break, here is the code

public  static void ReplaceSectionBreak(string sFilePath)
    Document doc = new Document(sFilePath);
    doc.FirstSection.Range.Replace("&b", "&l", 
	new Aspose.Words.Replacing.FindReplaceOptions()

But the fomat changed,it look like this
resultPreview.png (5.8 KB)

Here is my source word file:
sourcefile.docx (26.3 KB)

How can I solve my problem with aspose.word?

@gxhllj The problem occurs because you replace section break with manual line break. In this case paragraphs between section break are concatenated and formatting of one paragraph is applied (alignment and first line indent). To get the desired result you should use paragraph break &p instead of manual line break &l:

doc.Range.Replace("&b", "&p",  new Aspose.Words.Replacing.FindReplaceOptions());

Use paragraph break &p instead of manual line break &l will cause other problem .
You can try to use my demo and the test file

@gxhllj Could you please elaborate what problem you are talking about? Please attach your output and expected output documents? This will help us to better understand your requirements.

The source file look like this
src.PNG (3.3 KB)

I want to convert to like this
ok.PNG (2.2 KB)

But after I use the aspose , it look like this
p.png (2.7 KB)

the original test file is
1_ReplaceSectionBreak.docx (40.3 KB)

My demo
GuxhTestNew.zip (7.7 MB)

@gxhllj Thank you for additional information. As I can see you are using old 16.7 version of Aspose.Words. The problem is not reproducible with the latest 22.3 version of Aspose.Words.