Products Technologies Demo Docs Blog Support Company

Powerful Extension Methods to Handle Tracked Changes

This article shows how to implement powerful extension methods to remove all tracked changes in all text parts by a given username.

Powerful Extension Methods to Handle Tracked Changes

Since version X16, TX Text Control provides a way to track changes in documents made by multiple authors to enable document collaboration.

The TXTextControl.TrackedChange class represents a change made to the document after anyone has revised the document. It returns the TXTextControl.TrackedChange.UserName property, time stamps, the kind of the change and the content.

In order to accept or reject a tracked change, the specific change needs to be removed from the TXTextControl.TrackedChangeCollection class using the TXTextControl.TrackedChangeCollection.Remove method.

Sometimes, it is required to remove all changes from the whole document by a given Username. For this purpose, we implemented two extension methods. Extension methods enable you to add additional functionality to existing classes.

The following extension methods remove all changes from the TrackedChangeCollection or all changes from all TextParts:

namespace TrackedChangeCollectionExtensions
{
    public static class TrackedChangeCollectionExtensions
    {
        // removes all changes in the TrackedChangeCollection with a given username
        public static int RemoveAll(
            this TXTextControl.TrackedChangeCollection trackdChangeCollection, 
            string username, bool accept)
        {
            List<TrackedChange> myTrackedChanges = new List<TrackedChange>();

            // loop through all changes
            foreach (TXTextControl.TrackedChange trackedChange in trackdChangeCollection)
            {
                if (trackedChange.UserName == username)
                    myTrackedChanges.Add(trackedChange);
            }

            // delete all changes
            foreach (TrackedChange listedTrackedChange in myTrackedChanges)
                trackdChangeCollection.Remove(listedTrackedChange, true);

            return myTrackedChanges.Count;
        }

        // removes all changes in all TextParts with a given username
        public static int RemoveAllTrackedChanges(
            this TXTextControl.TextPartCollection textPartCollection, 
            string username, bool accept)
        {
            // counter
            var deletedTrackedChanges = 0;

            // loop through all text parts
            foreach (IFormattedText textPart in textPartCollection)
            {
                List<TrackedChange> myTrackedChanges = new List<TrackedChange>();

                // loop through all changes
                foreach (TXTextControl.TrackedChange trackedChange in textPart.TrackedChanges)
                {
                    if (trackedChange.UserName == username)
                        myTrackedChanges.Add(trackedChange);
                }

                // delete all changes
                foreach (TrackedChange listedTrackedChange in myTrackedChanges)
                {
                    textPart.TrackedChanges.Remove(listedTrackedChange, true);
                    deletedTrackedChanges++;
                }
            }

            return deletedTrackedChanges;
        }
    }
}

In order to accept all changes made by the user development@devteam.com, only the following call is required:

var removedChanges = textControl1.TrackedChanges.RemoveAll("development@devteam.com", true);

If you need to reject all changed in all text parts including the header, footer, main text and text frames, the following call can be used:

var removedChanges =
  textControl1.TextParts.RemoveAllTrackedChanges("development@devteam.com", false);

If you did not try version X16 already, please download a trial version and test this on your own.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Also See

This post references the following in the documentation:

  • TXTextControl.TrackedChange Class
  • TXTextControl.TrackedChange.UserName Property
  • TXTextControl.TrackedChangeCollection Class
  • TXTextControl.TrackedChangeCollection.Remove Method

ASP.NET

Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.

ASP.NET Core
Angular
Blazor
JavaScript
React
  • Angular
  • Blazor
  • React
  • JavaScript
  • ASP.NET MVC, ASP.NET Core, and WebForms

Learn more Trial token Download trial

Related Posts

ASP.NETWindows FormsWPF

Tracked Changes: Toggle Markup

Tracked changes is also known as red-lining - a way to track changes done by users to a document. Displaying the changes in various colors can be distracting. This demo code shows how to turn the…


ASP.NETWindows FormsWPF

TX Text Control 33.0 SP3 is Now Available: What's New in the Latest Version

TX Text Control 33.0 Service Pack 3 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…


ASP.NETWindows FormsWPF

TX Text Control 33.0 SP2 is Now Available: What's New in the Latest Version

TX Text Control 33.0 Service Pack 2 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…


ASP.NETWindows FormsWPF

Document Lifecycle Optimization: Leveraging TX Text Control's Internal Format

Maintaining the integrity and functionality of documents throughout their lifecycle is paramount. TX Text Control provides a robust ecosystem that focuses on preserving documents in their internal…


ActiveXASP.NETWindows Forms

Expert Implementation Services for Legacy System Modernization

We are happy to officially announce our partnership with Quality Bytes, a specialized integration company with extensive experience in modernizing legacy systems with TX Text Control technologies.