Categories
Bloggers
Blogs RSS feed

How to Display Email Campaign Issues on Sitefinity Pages

by Zheyna Peleva
In this blog post I'm going to show you how to place links to already sent Email campaign issues on your Sitefinity pages. The same approach can be used to link fallback versions of your campaigns, directly in the issue itself.

To achieve this, we need two simple user controls:

  • NewsLettersFront contains a repeater that lists all your issues. Since all Sitefinity newsletters campaigns have internal links, that aren't visible if you're not logged it, you don't have a link for each issue as there used to be in 5.1. This functionality is removed, because of security reasons. What we'll do is render the content of the issue on a Sitefinity page, which will simulate the issue being opened in the browser. The repeater lists anchor items with URLs, leading to some page, concatenated with a queryString, where we pass the id of the issue. As I mentioned, you pass the issue id in the queryString and you're redirected to some page. Then on this page you have the CampaignDetail widget.
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="NewsLettersFront.ascx.cs" Inherits="SitefinityWebApp.NewsLettersFront" %>
 
<asp:Repeater runat="server" ID="myRep">
    <HeaderTemplate>
        <div class="span11">
            <div class="quotestests">
    </HeaderTemplate>
    <ItemTemplate>
           <a href='<%# string.Format("nameOfPageForIssues?id={0}", Eval("Id")) %>' ><%#Eval("Name")%></a>
        <br />
    </ItemTemplate>
    <FooterTemplate>
            </div>
        </div>
    </FooterTemplate>
 
</asp:Repeater>

code-behind
namespace SitefinityWebApp
{
    public partial class NewsLettersFront : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var pManager = PageManager.GetManager();
            using (ElevatedModeRegion elevatedModeRegion = new ElevatedModeRegion(pManager))
            {
 
                NewslettersManager manager = NewslettersManager.GetManager();
                Campaign campaign = manager.GetCampaigns().Where(c => c.Name == "TestCampaign").SingleOrDefault();
                var issues = manager.GetIssues(campaign);
                var render = new InMemoryPageRender();
 
 
                myRep.DataSource = issues;
                myRep.DataBind();
 
            }
 
        }
 
    }
}


  • CampaignDetail handles the logic for getting the queryString parameter value and using it to retrieve the issue. I'm retrieving the issue by its id with the GetIssue() method of the NewslettersManager. After you have the issue, you get its html, and with ResponseWrite (passing the html) you recreate the issue on the page. This way it looks like you're opening the issue in a new page:
public partial class CampaignDetail : System.Web.UI.UserControl
   {
       protected void Page_Load(object sender, EventArgs e)
       {
           var pManager = PageManager.GetManager();
           NewslettersManager newsletterManager = NewslettersManager.GetManager();
           var render = new InMemoryPageRender();
           var queryStringId = Request.QueryString["id"];
           if (queryStringId != null)
           {
               Campaign issue = newsletterManager.GetIssue(new Guid(queryStringId));
               if (issue != null)
               {
 
                   var campaignMessageBody = issue.MessageBody;
                   var node = pManager.GetPageNode(campaignMessageBody.Id);
                   var text = render.RenderPage(node, false, isIndexMode: false);
                   var realHtml = HtmlProcessor.ProcessHtml(text);
 
                   Response.Write(realHtml);
                   Response.Write("<br/>");
               }
           }
 
       }
   }

As mentioned above, you can use this approach to place fallback campaign links directly on the emails, sent to your subscribers.

Hope you find the blog post useful!

7 comments

Leave a comment
  1. Jen Apr 22, 2013
    Amanda, please make sure that the issue you got is not empty, since this is the markup, which would be rendered by an empty email campaign issue.
  2. Amanda S. Apr 22, 2013
    Hi Jen
    When I check var campaingMessageBodyText = issue.MessageBody.BodyText; I'm able to see the content, so I'm fairly certain it's not blank.
    Maybe I should send in a support ticket for you guys to look at it?

    I think this is a great added functionality. One of the complaints I had head was that there was no 'archive' of the newsletter editions. So this will greatly help us.
  3. Jen Apr 23, 2013
    Hello Amanda!

    I'm glad that you found the blog post useful. As you mentioned already, opening a support ticket, will allow us to investigate this behavior further.
  4. Gawein May 09, 2013
    Hi,

    I am experiencing the same output as Amanda. I also get an empty div. But if I request issue.MessageBody.BodyText I do get the correct html code!
    What does render.RenderPage and HtmlProcessor.ProcessHtml do?
  5. Agen Bola Sep 16, 2013
    Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work
  6. Joshua Mar 22, 2014
    Thank you for sharing this! Just what I’ve been searching for. Great info!
  7. Andrew Mar 22, 2014

    Nice.

    Leave a comment