3

Lets suppose I have this 2 htmls

var p1 ="<h1>Title</h1>";
var p2 = "<h2>Title changed</h2>";

I need to generate an email with a visual difference, just something like what source control systems do with the content changed/added/deleted.

Basically the email needs to say what changed, what was added, what was deleted.

Obviosly the htmls will be more complex, I just wanted to illustrate what I need to do.

However, I am not sure, at what direction should I look, what are my options?

Fresh Saint
  • 139
  • 2
  • 12
Luis Valencia
  • 32,619
  • 93
  • 286
  • 506
  • Google `diff tool c#` – RB. Feb 03 '14 at 09:27
  • You may look into this question: http://stackoverflow.com/questions/138331/any-decent-text-diff-merge-engine-for-net There are some links to diff tools that work with c#. – Jojo Feb 03 '14 at 09:33

2 Answers2

2

You could use John Resig's algorithm to compare two strings: http://ejohn.org/projects/javascript-diff-algorithm/

Just download and include jsdiff.js in your script and run it like this:

var p1 ="<h1>Title</h1>";
var p2 = "<h2>Title changed</h2>";

document.body.innerHTML = diffString(p1, p2);
Emilio Rodriguez
  • 5,709
  • 4
  • 27
  • 32
  • +1, looks a nice option to look at – Luis Valencia Feb 03 '14 at 09:34
  • just a small question, I am generating emails with the result, first 1. Can I have javascripts embedded on emails?, 2. Here we dont have exchange, but lotus notes, not sure if that makes a difference. – Luis Valencia Feb 03 '14 at 09:35
  • well, Lotus Notes supports some sort of javascript execution but take into account that many users set this feature off since it can be a security hole – Emilio Rodriguez Feb 03 '14 at 09:39
  • 1
    DiffPlex is a better solution to compare 2 html pages: https://github.com/mmanela/diffplex and works well on C# – Denis Evseev Jan 22 '20 at 12:35
-1

Look into Winmerge .
WinMerge is an Open Source differencing and merging tool for Windows. WinMerge can compare both folders and files, presenting differences in a visual text format that is easy to understand and handle.

spetzz
  • 679
  • 8
  • 19
  • Does that have an API suitable for consumption in C#? If so, please link to it, otherwise this answer should probably be a comment... – RB. Feb 03 '14 at 09:28
  • It is for Manual Comparing only . For Automatic Comparing of Documents , you will have to write Code .. – spetzz Feb 03 '14 at 09:29
  • You can also look into this SO thread http://stackoverflow.com/questions/12505851/diff-tool-that-can-be-integrated-into-a-c-sharp-app – spetzz Feb 03 '14 at 09:31
  • 1
    that was kind of my point! He is looking for a way to automate this process through `c#`, as that is what has tagged the question with. – RB. Feb 03 '14 at 09:32
  • OK .. i misunderstood the question then .. Anyway the Link has the Relevant Answers .. – spetzz Feb 03 '14 at 09:34