This has recently been resolved in EPiServer 8:
In the publication event (in your example) that occurs before the page is published, it should work fine only with the ContentLoader service for comparison. ContentLoader will automatically download 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. Used only for pages that already exist, IE. new pages will have an empty ContentLink (ContentReference.Empty) within the argument.
Regarding the PublisherPage event that occurs after the page is published. You can use the following snippet to view 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) {
Note: this answer does not account for localization.
maets source share