Fluent API and pages

Posted by Community Admin on 04-Aug-2018 16:20

Fluent API and pages

All Replies

Posted by Community Admin on 31-Aug-2011 00:00

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.

Posted by Community Admin on 01-Sep-2011 00:00

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

Posted by Community Admin on 01-Sep-2011 00:00

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();

Posted by Community Admin on 01-Sep-2011 00:00

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>

Posted by Community Admin on 01-Sep-2011 00:00

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.

Posted by Community Admin on 07-Sep-2011 00:00

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();

Posted by Community Admin on 08-Sep-2011 00:00

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.

Posted by Community Admin on 08-Sep-2011 00:00

(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)

This thread is closed