Recently solved this in EPiServer 8:
In the publishing event (in your example), which occurs before the page is published it should work fine just using the ContentLoader service for comparison. The ContentLoader will automatically fetch the published version.
if (e.Content != null && !ContentReference.IsNullOrEmpty(e.Content.ContentLink))
{
var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
var publishedVersionOfPage = contentLoader.Get<IContent>(e.Content.ContentLink);
}
Note: Only applies to pages that already exists, IE. new pages will have an empty
ContentLink (ContentReference.Empty) within the e-argument.
As for the PublishedPage event, which occurs after the page is published.
You can use the following snippet to get hold of the previous published
version (if any):
var cvr = ServiceLocator.Current.GetInstance<IContentVersionRepository>();
IEnumerable<ContentVersion> lastTwoVersions = cvr
.List(page.ContentLink)
.Where(p => p.Status == VersionStatus.PreviouslyPublished || p.Status == VersionStatus.Published)
.OrderByDescending(p => p.Saved)
.Take(2);
if (lastTwoVersions.Count() == 2)
{
// lastTwoVersions now contains the two latest version for comparison
// Or the latter one vs the e.Content object.
}
Note: this answer does not take localization in account.