Fluent API and pages
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();
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
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();
Hmm.. I got a NullReferenceException was unhandled by user code on the line:
RadGrid2.DataSource = testpages;
<%@ 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
>
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())
....
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();
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.
(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)