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

Forums / Developing with Sitefinity / Fluent API and pages

Fluent API and pages

8 posts, 1 answered
  1. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    31 Aug 2011
    Link to this post
    Hi,

    I was trying to get my head wrapped around the fluent api and it's abilities, and was dabbling with the pages and ran into 2 questions, which hopefully someone can answer.

    This may not be the best code or preferred method, but like I said I'm just trying stuff...

    var testpages = App.WorkWith()
                        .Pages()
                        .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
                        .ThatArePublished()
                        .OrderBy(p => p.Ordinal)
                        .ForEach(p =>
                        {
                           ....
                        })
                        .Get();
    radgrid3.DataSource = testpages;
    radgrid3.DataBind();

    With this my Radgrid fills nicely, and the world is at bliss, inside the .ForEach i could for each p retrieve the htmltitle and other attributes: Response.Write(pageManager.GetPageData(p.PageId).Owner);
    neatly outputs the owner same goes for .PublicationDate and .LastModified but .LastModifiedBy gives me a blank... anybody can explain to me why?

    Also with a group page (a page that doesn't have content itself) the pageId is an empty GUID, how can one retrieve the title of that page through the .Pages() facade?

    Or (because it's not an actual page) keep it out of the resulting data?  I can't seem to find a way to filter it out or can this only be done by a .Where clause and filter on NodeType being standard.

    J.
  2. Dan Sorensen
    Dan Sorensen avatar
    256 posts
    Registered:
    13 Aug 2010
    01 Sep 2011
    Link to this post
    Can you elaborate on your example inside the .ForEach()? I'm interested in the syntax you put to get one of those attributes.

    I wish I had the answer, but I find your post informative.

    Thanks
  3. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    01 Sep 2011
    Link to this post
    Hey Dan,

    Below I've copy/pasted the entire snippit. Just drop it in Page_Load and put a RadGrid with the ID set to RadGrid2 on your page.

    As you can see I'm just dumping different data on the screen to try and understand what gives me what, but the group page has me stumped and not sure if the empty .LastModifiedby is a bug or a design.

    var pageManager = PageManager.GetManager();
     
    var testpages = App.WorkWith()
                       .Pages()
                       .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
                       .ThatArePublished()
                       .OrderBy(p => p.Ordinal)
                       .ForEach(p =>
                            {
                                try
                                    {
                                    Response.Write(" | HTMLTitle: ");
                                    Response.Write(pageManager.GetPageData(p.PageId).HtmlTitle);
                                    Response.Write(" | PN UrlName: ");
                                    Response.Write(pageManager.GetPageNode(p.Id).UrlName);
                                    Response.Write(" | PN GetUrl: ");
                                    Response.Write(pageManager.GetPageNode(p.Id).GetUrl());
                                    Response.Write(" | Status: ");
                                    Response.Write(pageManager.GetPageData(p.PageId).Status);
                                    Response.Write(" | LastModified by: ");
                                    Response.Write(pageManager.GetPageData(p.PageId).LastModifiedBy);
                                    Response.Write(" | LastModified on: ");
                                    Response.Write(pageManager.GetPageData(p.PageId).LastModified);
                                    Response.Write(" | Publication: ");
                                    Response.Write(pageManager.GetPageData(p.PageId).PublicationDate);
                                    Response.Write(" | Owner: ");
                                    Response.Write(pageManager.GetPageData(p.PageId).Owner);
                                    }
                                catch
                                    {
                                    }
                                Response.Write("<br/>");
                            })
                       .Get();
    radgrid2.DataSource = testpages;
    radgrid2.DataBind();
  4. Dan Sorensen
    Dan Sorensen avatar
    256 posts
    Registered:
    13 Aug 2010
    01 Sep 2011
    Link to this post
    Hmm.. I got a NullReferenceException was unhandled by user code on the line:

    RadGrid2.DataSource = testpages;

    I'm wondering if my ASCX code is incorrect or different from yours.

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SimpleMenu.ascx.cs" Inherits="SitefinityWebApp.Esd.Nav.BasicList.SimpleMenu" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
     
    <telerik:RadGrid ID="RadGrid2" runat="server">
    </telerik:RadGrid>
  5. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    01 Sep 2011
    Link to this post
    Hey Dan,

    Strange, I think it's more a code-behind issue which jumps to the error when trying to bind it. I've tried to clean up the code I used, and possibly you're missing one of the usings...

    using System;
    using System.Web.UI;
    using Telerik.Sitefinity;
    using Telerik.Sitefinity.Modules.Pages;
    using Telerik.Sitefinity.Web;
     
    namespace SitefinityWebApp.Widgets
        {
        public partial class notsofluent : System.Web.UI.UserControl
            {
            protected void Page_Load(object sender, EventArgs e)
                {
                if (!this.IsDesignMode())
                    {
                    ....
                    }
                }
            }
        }

    And I've got the previous code snippet right there in the middle. My .ascx is even shorter, I'm not registering Telerik.Web.UI but haven't configured the RadGrid it all or changed any settings. Just opened design view and dragged one on it.
  6. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    07 Sep 2011
    Link to this post
    I think the "Page" object of of p is null when it's a group page

    var testpages = App.WorkWith()
                       .Pages()
                       .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
                       .ThatArePublished()
                       .OrderBy(p => p.Ordinal)
                       .Get().ToList();
     
    var flatData = (from t in testpages
                    select new {
                        Title = (t.Page != null) ? t.Page.NavigationNode.Title.ToString() : "No Title",
                        UrlName = (t.Page != null) ? t.Page.UrlName.ToString() : "No URL",
                        FullURL = t.GetFullUrl(),
                        Type = t.NodeType.ToString(),
                        Status = (t.Page != null) ? t.Page.Status.ToString() : ""
                    });
     
    pageDataGrid.DataSource = flatData;
    pageDataGrid.DataBind();

    Answered
  7. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    08 Sep 2011
    Link to this post
    Hey Steve,

    Works like a charm!
    Thanks, I thought it was just me who couldn't retrieve just the pages on the first run, but I'm starting to have faith in my fluency now :)

    For the rest who reads this post, I've given up on the 'Modified by'. It doesn't get stored anywhere in the db either, no matter what mixture of create/edit/publish/workflow thing you try so I'm taking this as a 'not implemented yet' feature by Telerik.

    Jochem.
  8. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    08 Sep 2011
    Link to this post
    (side note)

    Perhaps I just can't find it, but it would be nice to be able to specify the page type you want in the fluent query instead of having to check for null

    .ThatAreOfType(Telerik.Sitefinity.Fluent.Pages.Types.Group)
8 posts, 1 answered