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

Forums / Developing with Sitefinity / Get the first content item on a page

Get the first content item on a page

4 posts, 0 answered
  1. LouiseBA
    LouiseBA avatar
    61 posts
    Registered:
    23 Mar 2010
    09 Aug 2011
    Link to this post
    Hi there, I need to write out the first few sentences of a given page as there is no descriptive field in the properties of a page that I can utilise. So it will be the first 'content block' that they add to that page (there will be at least one per page), and the first few characters from that content block. Is this possible using Page.Controls? Even so how do I know its the top content block they add (the first one at the top of the page is the one I want to grab)?

    thanks, Louise
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    10 Aug 2011
    Link to this post
    Hello Louiseba,

    Here is a sample code that illustrates how to get the fist control

    var pages = App.WorkWith().Pages().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
                .Where(p => p.Page != null&&
                            p.Page.Controls.Where(c => c.ObjectType.StartsWith(typeof(ContentBlock).FullName)).Count() > 0)
                .Get().ToList();
    // get the controls from each page
                foreach(var tnp in pages)
                {
                    var block = (from a intnp.Page.Controls.Where(p => p.ObjectType.StartsWith(typeof(ContentBlock).FullName)) select a).FirstOrDefault();
                   var c = man.LoadControl(block) ContentBlock;


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. LouiseBA
    LouiseBA avatar
    61 posts
    Registered:
    23 Mar 2010
    10 Aug 2011
    Link to this post
    Thanks, but what is 'man'??

    (actually i worked that bit out .. pagemanager !)

    And could you point me in the direction of how to then get the content that the user has added to the content block?

    thanks, Louise
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    10 Aug 2011
    Link to this post
    Hello Louiseba,

    Use the public properties of the ContentBlock

    http://www.sitefinity.com/40/help/developers-guide/properties_t_telerik_sitefinity_modules_genericcontent_web_ui_contentblock.html

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
4 posts, 0 answered