Saturday, December 22, 2007

Blogger.com as your blog engine!

About
This article is a short description of how to use blogger.com as your blog engine for your personal ASP.NET web page. I.e. an example of how to have a blogger.com account and write your blogs there and at the same time display your blog on another web page.

Problem
I was tired of developing my own blog/article engine so I wanted to use one of the existing ones (why reinvent the wheel?!) and then display the blog on my web page (www.bursjoo.se). My first approach was to use Windows Live Spaces (spaces.live.com). But the blog functionality was limited to one blog only, I wanted three (one for my personal blog, one for the tech-blog and one for my projects). Next I wanted an API for .NET and I wanted to use Windows Live Writer for writing blogs.

image

Solution
My choice of blog engine was blogger.com; part wise because of the very nice .NET API (Google Data API) that Google provides but also because blogger.com have great blogging functionality. After the API was downloaded and installed into a sample web project I wanted to create a web page with the following functionality:

1. A list of recent blogs.
2. A month/year-list for blog archive.
3. A page displaying the most recent blogs.
4. A page displaying a single blog-post and all its comments.
5. A structure of all the above so that a new blog could be added to a web site in a simple way.

This is the structure:
image

The topmost part is the Blog.aspx site. This site is the one that you can customize to fit your layout and make your blog look the way you want to. Technically the controls will call some method in the Blogger.cs file (GetRecentPosts, GetPost, GetArchive...). This class will then forward the question to blogspot.com via the Google Data API and retrieve the data.
To use several blogs on your web site you can create several files like Blog.aspx (e.g. Blog.aspx, Projects.aspx, Articles.aspx). In each of these files you set the path to the blog on blogspot (e.g. http://bursjooprojects.blogspot.com).

This example does not require you to login or pass any login-information to get the data. In other words this is a blog viewer and you can actually view other blogs than your own, you only have to provide the address to the blog you want to display. You can also not post to your blog account, use Windows Live Writer or the online blogspot.com interface.

One problem that I found when developing this example was that I wanted a visitor to be able to post comments to my posts on my site. This is kind of possible but there is one problem. Via the Google Data API, only the owner of the blog can post a comment to the blog (using login information via the API) and this means that all comments from my site will be displayed like it was I that posted the comment, not very pretty. So my solution is to put a link to the blogspot comment page, so that a user can comment the post via the blogspot.com interface. The reason why not anyone can post to your blog is that spam bots could then use the Google API to post spam to your blog. When you post a comment via the blogspot interface you must provide a captch-string and then spam bots can be stopped.

Download Source
Download the Visual Studio example here.

Examples
http://www.bursjoo.se/Blog.aspx - http://bursjoolife.blogspot.com
http://www.bursjoo.se/Project.aspx - http://bursjooprojects.blogspot.com
http://www.bursjoo.se/TechBlog.aspx - http://bursjootech.blogspot.com

Wednesday, December 19, 2007

DELL, MediaDirect and Outlook addin

If you have performance problems and have a computer from DELL with MediaDirect installed. Try to uninstall the plugin for Outlook. Run the .msi file in C:\Program Files\DELL\MediaDirect\OlAddin, choose to remove the plugin. This plugin also caused some very annoying folders (outlook calendar and outlook contacts) to be created everywhere. It also made the texteditor (when writing a new mail) very slow. I hope this will help someone!

Bind from XAML to a local property in code-behind

When I learned WPF I couldn´t figure out how to create a simple binding from my XAML to some property in my code-behind file. Now when I know I thought that I should share this small piece of knowledge and spare you the frustration that I had.

One way to create a binding is to bind to another element in your XAML-file. E.g. Text=”{Binding SomeProperty, ElementName=MyOtherElement}” where SomeProperty is a property in your MyOtherElement. MyOtherElement is the name (x:Name) of an element in your XAML-file. With this knowledge we just set a name on our root element (Window, Page, UserControl or whatever) x:Name="myRoot" and then refer to that name in ElementName. E.g Text="{Binding MyLocalProperty, ElementName=myRoot }". The MyLocalProperty is then a property in our code-behind file. This can be a standard property or a dependency property.

Download the sample project (BindToAPropertyDemo.zip).

Data Visualization in WPF

Windows Presentation Foundation is a tool for you to create great GUIs and presentation applications. One of the WPF projects that I have been involved in was to create an information visualization tool for presenting data (x-, y-, z-values, color and size). In other words this project was a 3D scatter plot that would give the impression of being 2D but also the ability to overview the data in 3D. I did this by switching between the build in projection cameras: Orthographic camera and Projection camera. This is the result:
3DChart2.png

3dChart1.png