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

Forums / Developing with Sitefinity / Getting 10 Last Modified Pages

Getting 10 Last Modified Pages

6 posts, 0 answered
  1. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    16 Oct 2007
    Link to this post
    What is the best way to fetch the 10 mostly newly updated pages?

    I know I can probably run a SQL statement against the table:

    SELECT ID FROM sf_pagecontentbase ORDER BY DateModified DESC LIMIT 10

    I'm guessing there is a better way to do this though.  I also thought about doing a:

    CmsManager manager = new CmsManager();  
    IList ourPages = manager.GetPages(); 

    And then sorting that IList. 

    Any advice would be welcome.

    Gabe
    -------------------
  2. Vassil Daskalov
    Vassil Daskalov avatar
    261 posts
    Registered:
    18 May 2013
    17 Oct 2007
    Link to this post
    Hello Gabe,

    Yes, getting all pages and sorting them is one of the possible solutions. In case you are using DataSource control, you could use the PagesDataSourceView object to get the needed pages. For example, if you want to bind the result in a data grid, you could do something like this:

    PagesDataSourceView pagesView = new PagesDataSourceView(new PagesDataSource(), String.Empty);  
     
    GridView grid = new GridView();  
    this.Controls.Add(grid);  
     
    grid.DataSource = pagesView.Select(new DataSourceSelectArguments("DateModified", 0, 3));  
    grid.DataBind(); 

    You should provide a dummy PagesDataSource object in the constructor's first value as this parameter cannot be null. Same is with the second parameter.

    Hope the code above is clear enough. Let me know if you need further assistance.

    Greetings,
    Vassil Daskalov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    25 Oct 2007
    Link to this post

    Hi Vassil,

    I used your code in a control I built.  It works fine while previewing the page within the Sitefinity Admin.  However, if I simply go to the public (published) URL for the page it returns 0 results.

    I'm doing all of this in the CreateChildControls() stage of my control.  Any idea why this works in the Admin view but not in the Public view?

    Thanks,

    Gabe
    ====================

  4. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    25 Oct 2007
    Link to this post
    This appears to have something to do with authentication.

    If I go straight to: http://localhost/ my control doesn't work.  It doesn't give an error, it simply returns zero results.

    However, if I go to http://localhost/sitefinity and login and THEN go to http://localhost/ everything works fine.

    There is nothing strange about the permissions I have set on all my pages.  In fact, I didn't change any of them from their default settings.

    Gabe
    ===================
  5. Yasen
    Yasen avatar
    121 posts
    Registered:
    18 May 2013
    29 Oct 2007
    Link to this post
    Hello Gabe,

    You are right about authentication. At the moment, the PageDataSourceView is designed to work only for the administration, so users that are not authenticated cannot take advantage of it. However, the fix for this is quite easy and a completely working version will be provided with the service pack next week.

    By then, you can use the CMSManager.GetPages() method from the Telerik.CMS assembly.

    Sorry for the inconvenience caused.

    Regards,
    Yasen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    03 Nov 2007
    Link to this post

    With the release of Service Pack 1 for Sitefinity 3.1 I had to give this another run.  It now works!

    I made a post regarding this to GoonDocks:

    http://www.goondocks.com/blog/07-11-03/sitefinity_what_s_new_control.aspx


    The code to do this looks something like this:

    CmsManager cms = new CmsManager();  
    IList RecentlyUpdated = cms.GetPages(0, NumberOfItems, "DateModified", System.ComponentModel.ListSortDirection.Descending, out totalRows, false);  
     

    Gabe
    ================
Register for webinar
6 posts, 0 answered