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

Free Support Forum - aspose.com

How to Delete Part of Paragraph Text using .NET | Track Changes

Hi - we are building a system where we rely heavily on manipulating DOCX files, using your tool. I currently have a situation where I would have paragraph with a single run, and I need to delete - lets say the bottom half of this text. Doing this by replacing the run range or setting the run text to the upper half results in aspose doing a full delete revision of the original text and then an insert revision for the updated text. The optimal scenario would be that the top part of the text remains untouched, and then the delete revision would only contain the lower half of the text

Can this be achieved somehow?

Best regards,
Kim

@kks4bed3

Please note that Aspose.Words mimics the behavior of MS Word. If you perform the same scenario using MS Word, you will get the same output. You need to stop the track changes and then replace the text.

If you still face problem, please share your input, problematic and expected output documents along with simplified code example that generates the problematic document. We will investigate the issue and provide you more information on it.

Hi Tahir,
I’m not sure I completely agree with that - when I, using MS Word, on a protected file (track changes enabled) select the last part of a paragraph and delete it it creates a delete revision including only the text selected, it does not result in a full delete revision of the entire paragraph, and then an insert revision of the text that was NOT selected. But I’m not referring to behavior of MS Word itself, not the programming model.
Our challenge with the way that ASPOSE handles this that it is technically a correct visualization with a full strikeout/deletion of the original text and an insertion of the “remaining” text, but it will confuse our users that they see both a delete and an insert revision, since they only deleted some text

Best regards,
KIm

@kks4bed3

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Console application and documents.zip (8.8 MB)

Hi Tahir,
Have now attached console application and documents. Please note that I had to delete the nuget package folder from the project, since it would break the 50mb upload limit

Best regards,
Kim

@kks4bed3

You are facing the expected behavior of Aspose.Words. When you set the text of Run node, Run.Text property removes the run’s text and insert new text.

We suggest you please use the following code example to get the desired output.

var document = new Document(MyDir + "TestDocument.docx");
var paragraph = document.GetChildNodes(NodeType.Paragraph, true).Cast<Paragraph>().ToList().FirstOrDefault();

document.StartTrackRevisions("system");
paragraph.Range.Replace("This is line 3 in a single paragraph document&lThis is line 4 in a single paragraph document", "", new FindReplaceOptions());
document.StopTrackRevisions();
document.Save(MyDir + "21.6.docx");

Hi Tahir,
That does make sense - I tried the replace function, but only for replacing the entire paragraph range text with the new one, resulting in a full strikeout/insertion. I can see that replacing only part of the text (as you showed above) with “” actually does the trick. Thank you so much!

Best regards,
Kim