Sending an Email with an Edit Page-link

Back from 2 healthy weeks of vacation on Iceland. Time to start blogging again!

This time I want to share a simple but useful snippet of code that sends an email to an EPiServer editor with a link that opens the page for editing in EPiServer Edit Mode.

How to create a go to Edit Mode link and mail it

string baselink = UriSupport.AbsoluteUrlFromUIBySettings("edit/");
string editlink = baselink + "SwitchLanguage.aspx?language=" + page.LanguageBranch +
  "&epUrl=" + Server.UrlEncode(baselink + "default.aspx?id=" + page.PageLink.ToString());
string pageurl = string.Format("<a href=\"{0}\">Edit '{1}'</a>", 
  editlink, page.PageName);


  string.Format("[Moderate] {0}", message),
  @"<html><body><h1>{0}</h1><p>The page<b>'{1}'</b> must be review and published.</p>" +
  @"<p>Log in to EPiServer Edit Mode and use the following ID in the bottom left search box:<br/>" +
  @"ID: <b>{2}</b></p>" +
  @"<p>Or click on the following link to login and review the page:<br/>{3}</p>",
  new object[] {message, page.PageName, page.PageLink.ID, pageurl}));

Works with unpublished versions of pages

The code above expects a PageData object in the page variable. It handles WorkPageID if you send in a page that is just saved or retrieved through PageVersion class.

Read more about How to work with Unpublished PageData from code in a previous blog post!

As usual, please leave a comment if you find it useful or have something to add. It is good for my blogging morale. 🙂