Sort News by Date in Sitefinity Admin

Posted by Steve Webb on Monday, November 07, 2011

Okay, the Sitefinity 4.0 launch was a little rocky or more like the family car being driven off a cliff but now that the dust has settled it is starting to look more like the Mercedes promised by the Telerik folks. Don't get me wrong there are still a lot of problems with the solution but it is by comparison much better at 4.2 SPx. There is still one nagging issue, among many others, that is really getting to me and that is the default sorting of news and blogs.

News and blogs are chronologically based. Both would not make much sense without a date associated to the content so why is it sorted alphabetically in the Sitefinity admin? You won't find the answer here but what you will find is a quick and dirty hack of a solution.

The reason I came up with this is that one of my recent clients has over 10,000 news articles and it is growing by about 50 to 100 a day. These articles were being imported from a 3rd party source and then a few select articles are being published as content on my client's site. With over 10,000 articles sorted alphabetically instead of chronologically good luck finding the newly added articles. After about a half hour of noodling on it I came up with the following solution.

The Solution

  1. Open/Add a Global.asax file in the root of your Sitefinity solution.
  2. Add the following code:
    protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
    {
               if (Request.Url.PathAndQuery.ToLower().StartsWith("/sitefinity/services/content/newsitemservice.svc") && Request.Url.PathAndQuery.ToLower().Contains("sortexpression=title%20asc") && Request.UrlReferrer.PathAndQuery.ToLower().Contains("/sitefinity/content/news") && !Request.Url.PathAndQuery.ToLower().Contains("/sitefinity/services/content/newsitemservice.svc/batch/?managertype"))
                    Response.Redirect(Request.Url.PathAndQuery.Replace("sortExpression=Title%20ASC","sortExpression=DateCreated%20DESC"));
    }

How it Works

It's pretty straight forward. Sitefinity makes service calls to populate the grid element in the Sitefinity admin area. Part of that call has a sort parameter so all this does is intercept that service request and redirect it to the same location with a different sort expression. Ideally, by now Sitefinity would have just changed that default sort parameter and this would not be required.


Go Back

Okay, the Sitefinity 4.0 launch was a little rocky or more like the family car being driven off a cliff but now that the dust has settled it is starting to look more like the Mercedes promised by the Telerik folks. Don't get me wrong there are still a lot of problems with the solution but it is by comparison much better at 4.2 SPx. There is still one nagging issue, among many others, that is really getting to me and that is the default sorting of news and blogs.

News and blogs are chronologically based. Both would not make much sense without a date associated to the content so why is it sorted alphabetically in the Sitefinity admin? You won't find the answer here but what you will find is a quick and dirty hack of a solution.

The reason I came up with this is that one of my recent clients has over 10,000 news articles and it is growing by about 50 to 100 a day. These articles were being imported from a 3rd party source and then a few select articles are being published as content on my client's site. With over 10,000 articles sorted alphabetically instead of chronologically good luck finding the newly added articles. After about a half hour of noodling on it I came up with the following solution.

The Solution

  1. Open/Add a Global.asax file in the root of your Sitefinity solution.
  2. Add the following code:
    protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
    {
               if (Request.Url.PathAndQuery.ToLower().StartsWith("/sitefinity/services/content/newsitemservice.svc") && Request.Url.PathAndQuery.ToLower().Contains("sortexpression=title%20asc") && Request.UrlReferrer.PathAndQuery.ToLower().Contains("/sitefinity/content/news") && !Request.Url.PathAndQuery.ToLower().Contains("/sitefinity/services/content/newsitemservice.svc/batch/?managertype"))
                    Response.Redirect(Request.Url.PathAndQuery.Replace("sortExpression=Title%20ASC","sortExpression=DateCreated%20DESC"));
    }

How it Works

It's pretty straight forward. Sitefinity makes service calls to populate the grid element in the Sitefinity admin area. Part of that call has a sort parameter so all this does is intercept that service request and redirect it to the same location with a different sort expression. Ideally, by now Sitefinity would have just changed that default sort parameter and this would not be required.

  • Facebook
  • Twitter
  • DZone It!
  • Digg It!
  • StumbleUpon
  • Technorati
  • Del.icio.us
  • NewsVine
  • Reddit
  • Blinklist
  • Add diigo bookmark