+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Display latest Blog Post

Display latest Blog Post

3 posts, 0 answered
  1. Tristan
    Tristan avatar
    22 posts
    Registered:
    30 Mar 2009
    02 Dec 2010
    Link to this post
    Hi,

    I'm trying to write a custom control to just display the latest blog post. I have created a new class and put it in the App_Code folder and referenced it in the web.config. however I get an error in the toolbox saying "Error loading control". Can anyone give me suggestions?

    My code is below

    Web.Config: <add name="Latest Single Blog" section="Blogs" type="Telerik.Blogs.Webcontrols.LatestSingleBlog, App_Code"/>

    using System;
    using System.Data;
    using System.Configuration;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using Telerik.Cms.Web;
    using Telerik.Cms.Engine;
    using Telerik.Cms.Engine.ContentViewFiltering;
    using System.Collections;
    using Telerik.Web;
    using Telerik.Blogs;
     
    /// <summary>
    /// Summary description for LatestBlogs
    /// </summary>
    ///
    namespace Telerik.Blogs.WebControls
    {
        public class LatestSingleBlog : Telerik.Blogs.WebControls.BlogPosts
        {
            public override string ItemListTemplatePath
            {
                get { return "~/Sitefinity/ControlTemplates/Blogs/ContentViewItemList.ascx"; }
            }
     
            public override string SingleItemTemplatePath
            {
                get { return "~/Sitefinity/ControlTemplates/Blogs/ContentViewSingleItem.ascx"; }
            }
     
     
            protected override void CreateChildControls()
            {
                var man = new BlogManager("Blogs");
                 
                var listofAll = man.Content.GetContent("Publication_Date DESC");
                var latestContent = listofAll[0] as IContent;
                 
                if (Context.Items.Contains(this.Manager.Provider.ContentItemKey))
                    itemId = (Guid)((IUrlRewriteData)Context.Items[Manager.Provider.ContentItemKey]).Data;
                else if (!String.IsNullOrEmpty(Context.Request[ContentItemKey]))
                    itemId = new Guid(Context.Request[ContentItemKey]);
                else
                {
                    itemId = latestContent.ID;
                }
                if (this.itemId != Guid.Empty && SingleModeSupported)
                {
                    ContentFilterBuilder filterBuilder = new ContentFilterBuilder(this);
                    filterBuilder.AddFilter(new ContentFilterStatement("ID", itemId.ToString(), ContentFilter.Condition.Equal,
                    ContentFilter.JoinType.And));
                    Controls.Add(SingleContainer);
                
                 
                base.CreateChildControls();
            }
        }
    }
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Dec 2010
    Link to this post
    Hi Tristan,

    Error loading control could be thrown in the type of the registered control is not valid. Could you try to remove the namepace and register the control as shown below

    <add name="Latest Single Blog" section="Blogs" type="LatestSingleBlog, App_Code" />

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Tristan
    Tristan avatar
    22 posts
    Registered:
    30 Mar 2009
    02 Dec 2010
    Link to this post
    Bingo. Thanks Ivan, I removed the namespace from the class and registered it as you suggested and works perfectly.

    Thanks again.
Register for webinar
3 posts, 0 answered