API access to URLs of posts

Topics: Business Logic Layer
Aug 24, 2008 at 2:41 PM
Hi all,

     I am using blog engine in my web application for the blogs. The rest of the website is an ASP.NET application. I want to put links to the latest blog posts in the application (on the pages that are outside the blog). Does blog engine expose any APIs that I can use to accomplish this task? I figured out that I could query the 'be_Posts' table in the blog engine database for a list of the blog posts and construct the URL of the post (by appending  /post/<year>/<month>/<slug>). Is there a better way?

Thanks,
Vandana
Aug 24, 2008 at 6:12 PM
Sure, use the RSS feed i.e.:

string latestPostTitle;
string latestPostLink;

WebRequest http = WebRequest.Create("http://www.domain.com/syndication.axd");
WebResponse response = http.GetResponse();
XmlDocument doc = new XmlDocument();
doc.Load(response.GetResponseStream());

XmlNodeList items  = doc.SelectNodes("/rss/channel/item");
foreach (XmlNode post in items) {
    latestPostTitle = post.SelectSingleNode("title").InnerText;
    latestPostLink = post.SelectSingleNode("link").InnerText;
    break;
}

... to get the most recent post. I think you can figure out how to get more.

Best regards
Rickard Nilsson
http://rickardnilsson.net
Aug 24, 2008 at 6:18 PM
Edited Aug 24, 2008 at 6:20 PM
But you can also go:

BlogEngine.Core.Post.Posts[0];

to get the actual object if you want to manipulate it in some way. But then you need a reference to the BlogEngine.Core dll.
Use the post.RelativeLink property to get the href.