More in this section

Forums / Developing with Sitefinity / auto generated newsletter

auto generated newsletter

4 posts, 0 answered
  1. TLsf
    TLsf avatar
    6 posts
    Registered:
    10 Jul 2008
    30 Sep 2008
    Link to this post
    Hello,

    We are trying to come up with a way to auto-generate a newsletter with information from the News and Events modules. Ideally we would be able to specify which categories of News and Events to return, and the fields: Title, Summary, Content, Date... and get formatted HTML code in return which we can paste in the Newsletter module.

    Does anyone have already finished code that extracts News and Events or has done something similar that can get us started? Any help will be much appreciated.
  2. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    30 Sep 2008
    Link to this post
    this is pretty straightforward with the content APIs. I don't have a completed example you could borrow but I did something similar to build an rss feed of a custom module...

    basically you just need to use the api to get a collection of events/news/etc then iterate through each one and build the html.

    an example of the api is here: http://www.sitefinity.com/help/developer-manual/news-api-walkthrough.html which covers the news. here's a relevant snippet:

    // create new instance of NewsManager  
    Telerik.News.NewsManager newsManager = new Telerik.News.NewsManager("News");  
    // get all news content items  
    IList listOfNewsItems = newsManager.Content.GetContent();  
    if (listOfNewsItems.Count > 0)  
    {  
     foreach(Telerik.Cms.Engine.IContent newsItem in listOfNewsItems)  
         Response.Write(newsItem.GetMetaData("Title") + "<br />");  

    your code would go in place of that last line to build the html using the various MetaData items for the News item.

    here's the link for events: http://www.sitefinity.com/help/developer-manual/events-api-finding-events.html

    you can wrap these into a GetNewsletter method that returns the built html.

    hope that this was helpful!
  3. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    30 Sep 2008
    Link to this post
    Hello,
    Josh beat me to the punch. Here's how to get the content items from given category though:
            IList listOfNewsItems = newsManager.Content.GetContent("[CategoryName] ASC");  
            if (listOfNewsItems.Count > 0)  
            {  
                foreach (Telerik.Cms.Engine.IContent newsItem in listOfNewsItems)  
                {  
                    NetmediaPanel1.Text += newsItem.GetMetaData("Title") + "<br />";  
                    //news1.Text += newsItem.GetMetaData("Category") + "<br />";  
                    NetmediaPanel1.Text += newsItem.Content.ToString() + "<br /><br />";  
                }  
            }  

    Josh, we have updated your Telerik account for a helpful reply. Thanks!

    Best wishes,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  4. TLsf
    TLsf avatar
    6 posts
    Registered:
    10 Jul 2008
    01 Oct 2008
    Link to this post
    Thank you to both of you. This was really helpful. I'll give it a go.
Register for webinar
4 posts, 0 answered