Open lastest post automatic as the default.aspx

Topics: ASP.NET 2.0
Aug 9, 2008 at 8:37 AM

Instead of a list of posts on the default page, I would like the lastest post to open automatically. Any ideas how ?

Thanks,
Gavin

http://blog.i386.com
Aug 11, 2008 at 3:40 AM
You would have to recode the default.aspx.cs to accomplish this.  Here is a quick and dirty example on how to display only the first post...

change this:
PostList1.Posts = Post.Posts.ConvertAll(new Converter<Post, IPublishable>(delegate(Post p) { return p as IPublishable; }));

to this...
 List<IPublishable> Posts = new List<IPublishable>();
 Posts.Add(Post.Posts[0]);
PostList1.Posts = Posts;


           
Aug 12, 2008 at 2:41 PM
Edited Aug 12, 2008 at 2:53 PM
Thanks, Alex

I added the following code, I got summary of the last article to show, half way there, hoping to display the entire post :)

 (I'm using 1.3.1 haven't upgrade to 1.4 yet, if that matters)

using System.Collections.Generic;

        //    PostList1.Posts = Post.Posts;
       
            List<Post> Posts = new List<Post>();
            Posts.Add(Post.Posts[0]);
            PostList1.Posts = Posts;

But it gives me a idea to change the post.aspx.cs file code. So that what post.aspx is called without variables (folders/pages etcs) it will open the last post.

Add 'using System.Collections.Generic' to the post.aspx.cs

Replace the

        if (Request.QueryString["id"] != null && Request.QueryString["id"].Length == 36)
        {
            Guid id = new Guid(Request.QueryString["id"]);
            this.Post = Post.GetPost(id);
With

        if ((Request.QueryString["id"] != null && Request.QueryString["id"].Length == 36 || Request.QueryString.Count==0))
            {
                if (Request.QueryString.Count == 0)
                {
                    List<Post> Posts = new List<Post>();
                    this.Post = Post.Posts[0];

                }
                else
                {
                    Guid id = new Guid(Request.QueryString["id"]);
                    this.Post = Post.GetPost(id);
                }


That's it, it works.   Maybe I'll submit it as a new feature :)

Gavin