Post category based on start/end time

Topics: ASP.NET 2.0
Apr 28, 2011 at 4:41 PM

Hey Guys,

I am pretty new to blogengine. Nice App!

I want my posts to change categories based on a post expiration date.

eg: I create two news categories named "Breaking News"and Archived News". I create a post with category "Breaking News"and enter start time for post as say Mar 30, Mon 9:00 am AND end time as Mar 31, Tue 9:00 am - I want that post to initially display in the "Breaking News" category and change to the "Archived News" category at the end time. 

Basically - I want to setup my posts to act similiar to this discussion except I 'd need the posts to change the category (not the IsPublished property) based on a post expiration date.

Is this possible? How do i implement it? I appreciate any help! Thanks


Apr 28, 2011 at 7:51 PM

Not a real code, but basically I'd modify "OnInit" in the ~/post.aspx.cs to somehing like this:  

if (post != null)
// start new code
if (DateTime.Now > post.DateCreated + 7) // more than week old
    post.Categories.Remove("Breaking News"); 
// end new code
You can assign "breaking" category alongside with normal, real category that would remain intact after "breaking" removed.
Apr 29, 2011 at 3:35 PM

Thanx Rtur! I'll give this a try and let you know how it turned out.

May 10, 2011 at 9:52 PM

Rtur -  can't seem to get it to work. I understand that logic but I'm not a pro programmer and can't seem to get the the correct syntax. This is what I have so far:

   if (post != null)
                // start new code

                if (DateTime.Now > post.DateCreated.AddDays(7)) // more than week old

                // end new code

The program builds without errors except for this line:      post.Categories.Remove("Breaking");  I understand that it is not real code but this is line what i'm having trouble getting correct programmatically and syntax wise.


I get the following errors:

Error    1    The best overloaded method match for 'System.Collections.Generic.List<BlogEngine.Core.Category>.Remove(BlogEngine.Core.Category)' has some invalid arguments    

Error    2    Argument '1': cannot convert from 'string' to 'BlogEngine.Core.Category'   


I appreciate it. any help with that?



May 16, 2011 at 3:29 PM

hey.. anything on this?

May 23, 2011 at 8:50 PM

Anybody have advise on this?

May 24, 2011 at 5:04 AM
Edited May 25, 2011 at 2:05 AM

Try this:


var c = Category.Categories.FirstOrDefault(category => category.Title.Equals("Breaking"));

if (c != null)
{  post.Categories.Remove(c); }