Blog Posts on my parent site home page

Mar 4, 2009 at 7:23 PM
Hi

i have a site that currently has blogengine.net as sub application to a parent website.  On the default.aspx main home page of that parent I want to be able to show a summary the most recent blog post .  ie Blog entry title, author, date and the first few hundred characters of the post.  Is this possible and how would i go about it if anyone has tried?

thanks,
jj
Mar 5, 2009 at 11:32 AM
ive kind of got it worked out what I need to do.. the only thing i wandering is it possible to extract easily into an object that I an then bid as a DataSource to a repeater control a summary of blog posts.

I am after a recordset of the 10 most recent blog posts sorted by data in desending order that contains the Title, Author, Description, PubDate where isPublished = true

is there a property of the Blogengine.core or something that copuld help me?

thanks,
Coordinator
Mar 5, 2009 at 6:07 PM
Do you have a DataTable of the recent blog entries?  Or is it a (generic) collection of Post objects?

If you have a DataTable, you should be able to bind the data to a repeater.  E.g.
<%# Eval("Title") %>

If you're working with a collection of Post objects, probably Title, Author, Description etc are public properties which should be bindable.  Same syntax:
<%# Eval("Title") %>
Mar 5, 2009 at 6:37 PM
Hi BenAmada

thanks for helping me out one again...

im ok with the binding etc.. the issue i am having is how to get a list of the 10 most recent published blog posts and there associateted Title, Author ad Description ...  I figured if I could get them into a DataTable I would be ok as i am used to workng with those.. but if there is a more convient way within the BlogEngine core then i would prefer to use that.
ta,
jj
Coordinator
Mar 5, 2009 at 7:00 PM
You're going to be displaying the recent posts from a parent application which is not a BE application, right?

Where are you storing the posts ... in XML files or a SQL database?  If it's a SQL database, it would be pretty easy to run a query to retrieve the recent blog posts.

If the posts are in XML files, from your parent application, you could read those XML files.  But, this could be inefficient because you wouldn't easily be able to determine when a post is modified or a new post is added ... and so you would keep re-checking/re-reading the App_Data\posts folder of the BE child application.

If you're posts are in XML files (or even in a SQL DB), one idea is to create an extension that subscribes to the Post.Saved event, and whenever a post is saved, you notify the parent application of the change.  There's several ways to do this.  One way is to create a web service in the parent application that this new extension calls and passes in the information about the updated post.  The web service then saves the updated post details in its own file.

Another option not using a web service is for this new extension to update a separate "recent posts" file in the App_Data folder whenever a post is updated, saved, deleted.  This recent posts file would contain the names of the XML files (or Post guids) of the most recent posts.  Your parent application can have the most recent posts stored in cache with a cache dependency on that recent posts file in the child BE application.  When that recent posts file gets updated, the recent posts will be cleared out of the parent application's cache.  The parent application then checks the recent posts file and puts the updated recent posts back into cache.

So, a number of options are available ...
Mar 5, 2009 at 9:13 PM
yes sorry I didnt explain myself very well..

i am indeed using XML files...  with SQL it would have been very easy for me to do... and yes the parent application is not a BE application.

What ive done. is as follows. (probably not the most efficient but it will work for me!!)

i wrote a function in my parent application that returns an ArrayList of BlogPost objects.. by looping through all the files in the BE application 'App_Data/posts' folder (ignoring any that have not been modifed for a ages or that are un-published) and picking out the nodes from each xml file i was after.

i could then bind the ArrayList to a  repeater control for displaying the data.  Taken me a while to get my head around the xml but it seems to work ok.

thanks again...

Coordinator
Mar 5, 2009 at 11:29 PM
It's good to see you've gotten it all figured out.  As I mentioned, there's several ways to accomplish this.  If your site has a lot of traffic, down the road you can always work on improving performance, etc.