Friday, February 4, 2011

InfoPath 2007/2010: Tracking Changes in InfoPath

One of the coolest solutions in my InfoPath How-To book is the tracking of changes within a form. Although this requires code-behind the results are well worth the effort. Although my latest solution is for InfoPath 2010, you can use the same code and concepts in InfoPath 2007. My original solution was indeed in InfoPath 2007.

While writing the solution for the book, I realized I did not have the latest code and that there were some missing steps that I coded at the client site to handle line breaks. Have no fear! I am now working for that previous customer and reviewed the code that I was missing.

On Page 280 of my book, there is Listing 18.5. You'll see the "Get the Changes" line which calls the Diff method of the SPDiffUtility. Before this line, enter the following:

oldValue = oldValue.Replace("\n", SPDiffUtility.ChangeOpenTag + "<br></br>" + SPDiffUtility.ChangeCloseTag);
newValue = newValue.Replace("\n", SPDiffUtility.ChangeOpenTag + "<br></br>" + SPDiffUtility.ChangeCloseTag);


You'll need to declare oldValue and newValue prior to these lines. You can set these to the event values e.OldValue and e.NewValue. Without using these replace statements, any line breaks in the original text do not get reflected in the track changes text. Replacing the line breaks (\n) with the html shown above preserves the new lines in the tracked changes.


If you found this useful, please help support my SharePoint and .NET user group (Philly SNUG) by clicking on the logo below.

No comments:

Post a Comment

Matched Content