More in this section

Forums / Developing with Sitefinity / Getting the Last Modified List

Getting the Last Modified List

9 posts, 0 answered
  1. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    01 Jun 2011
    Link to this post
    Here's my query...

    var pages = App.WorkWith().Pages()
                              .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
                              .Where(x => x.NodeType == Telerik.Sitefinity.Pages.Model.NodeType.Standard)
                              .ThatArePublished()
                              .OrderByDescending(x => x.LastModified)
                              .Take(this.Count)
                              .Get().ToList();

    It seems to be returning like a random 5 items somewhere in the middle of the dataset instead of the last 5 modified pages

    What am I doing wrong with it...?
  2. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    01 Jun 2011
    Link to this post
    Also...is there no way to get the URL with the Pages Fluent (like with that manager)?
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    01 Jun 2011
    Link to this post
    Hello Steve,

    Try adding the ContentLifecycleStatus.Live to your query. The PageNode has a property Urls which you can use to get the page url. Urls returns IList of UrlData where you can call RedirectToDefault (Gets or sets a value indicating whether to redirect this URL to the default URL.)

    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. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    01 Jun 2011
    Link to this post
    Thanks Ivan...

    What about the first post though...

    What am I doing wrong in that fluent query where it's not giving me the top X last modified pages?
  5. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    30 Oct 2017
    02 Jun 2011
    Link to this post
    Hello Steve,

    Can you try with the blow code sample and let me know if the problems still persist?
    var lastTwo = App.WorkWith().Pages().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
                                                  .Where(pG => pG.Page.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).Get()
                                                  .OrderByDescending(pG => pG.Page.LastModified).Take(2)                                           
                                                  .ToList();


    Greetings,
    Boyan Barnev
    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
  6. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    02 Jun 2011
    Link to this post
    I'll give it a try...

    I was under the assumption that everything before the GET is what OA compiles into it's query, so I was putting that at the end...this looks like it'll get everything from the DB then just order and filter out all but the last couple items?
  7. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    30 Oct 2017
    03 Jun 2011
    Link to this post
    Hi Steve,

    Did you have the time to test the provided sample? Please get back to me if it does not suit the desired functionality, or you have some additional questions.

    Regards,
    Boyan Barnev
    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
  8. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    03 Jun 2011
    Link to this post
    Epic fail :)

    Server Error in '/' Application.

    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 23:         public void OnRecentUpdateList_NeedsDataSource(object sender, RadListViewNeedDataSourceEventArgs e) {
    Line 24:             var recentUpdates = App.WorkWith().Pages().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
    Line 25:                                               .Where(pG => pG.Page.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).Get()
    Line 26:                                               .OrderByDescending(pG => pG.Page.LastModified).Take(this.Count)
    Line 27:                                               .ToList();

    Source File: C:\My Dropbox\Projects\Leap\OCFP\Web\UserControls\RecentUpdates\RecentUpdates.ascx.cs    Line: 25

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       SitefinityWebApp.UserControls.RecentUpdates.RecentUpdates.<OnRecentUpdateList_NeedsDataSource>b__0(PageNode pG) in C:\My Dropbox\Projects\Leap\OCFP\Web\UserControls\RecentUpdates\RecentUpdates.ascx.cs:25
       System.Linq.WhereEnumerableIterator`1.MoveNext() +155
       System.Linq.Buffer`1..ctor(IEnumerable`1 source) +487
       System.Linq.<GetEnumerator>d__0.MoveNext() +145
       System.Linq.<TakeIterator>d__3a`1.MoveNext() +375
       System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +471
       System.Linq.Enumerable.ToList(IEnumerable`1 source) +79
       SitefinityWebApp.UserControls.RecentUpdates.RecentUpdates.OnRecentUpdateList_NeedsDataSource(Object sender, RadListViewNeedDataSourceEventArgs e) in C:\My Dropbox\Projects\Leap\OCFP\Web\UserControls\RecentUpdates\RecentUpdates.ascx.cs:24
       Telerik.Web.UI.RadListView.OnNeedDataSource(RadListViewNeedDataSourceEventArgs e) +197
       Telerik.Web.UI.RadListView.AutoDataBind(RadListViewRebindReason rebindReason) +183
       System.Web.UI.Control.LoadRecursive() +70
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3047
    
  9. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    30 Oct 2017
    08 Jun 2011
    Link to this post
    Hello Steve,

    Thank you for pointing that out, forgot to include the check for group pages in the sample (since they don't have PageData object). Please find below the revised sample:
    var lastTwoPages = App.WorkWith()
                          .Pages()
                          .Where(p => p.Page != null && p.Page.Status == ContentLifecycleStatus.Live)
                          .Get()
                          .OrderByDescending(pG => pG.Page.LastModified).Take(2)
                           .ToList();


    Kind regards,
    Boyan Barnev
    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
9 posts, 0 answered