Sep 14

 

DateTime Format for Blog Posts for BlogEngine.NET

...or wherever you want to standardize output formatting.

Here is a rather simple solution to my issue of Date Time formatting on my blog posts.  I noticed that as of a recent version of BlogEngine.NET, the Date looked something like this: "29. June 2008 09:00"  I wanted to change it to something more readable to my target readers, some very local, such as: "Sunday, June 29, 2008 09:00 AM".  Well, I might want to change it sometime, AND I would like to drop it into multiple Themes, so I decided to place the format in Web.Config AppSettings. I looked up my specific Format and added an appSetting.  Then I just replaced the code used in "PostView.ascx" and tested away.

Here's what you can do to implement this yourself.

  1. Go to .NET Framework Developer's Guide, Custom Date and Time Format Strings and/or locate your format string.
    • I used "dddd, MMMM dd, yyyy hh:mm tt"
  2. Create an appSettings key such as: Custom.DateFormat and assign your format to the value.
    • <add key="Custom.DateFormat" value="dddd, MMMM dd, yyyy hh:mm tt" />
  3. Now add the code to use the format string.
    • <%=Post.DateCreated.ToString(ConfigurationSettings.AppSettings["Custom.DateFormat"])%>
    • original: <%=Post.DateCreated.ToString("d. MMMM yyyy HH:mm") %>


This is what it looks like:

Web.Config ...

<add key="Custom.DateFormat" value="dddd, MMMM dd, yyyy hh:mm tt" />
</appSettings>

PostView.ascx ...

<span class="author">by <a href="<%=VirtualPathUtility.ToAbsolute(" mce_href="<%=VirtualPathUtility.ToAbsolute("~/") + "author/" + Post.Author %>.aspx"><%=Post.AuthorProfile != null ? Post.AuthorProfile.DisplayName : Post.Author %></a></span>
<span class="pubDate"><%=Post.DateCreated.ToString(ConfigurationSettings.AppSettings["Custom.DateFormat"])%></span>

DateTimeSnippet

 

You can add appSettings directly in Web.config, from IIS Manager, if ASP.NET configuration is available, or from "ASP.NET Web Site Administration Tool".  Although this solution was quick and dirty, the best answer may be to role localization into BlogEngine.NET using cultures.  This is not a specialty of mine so I would appreciate any suggestions on this topic.  It is likely only a few more lines of code for a "quick and dirty" approach but I'd rather make sure to do it right.

Aug 15

Here's the quick and dirty way to TURN OFF or DISABLE the "Shutdown Event Tracker" on Windows Server 2008 for all your test, development and virtual servers.

[Note: For Windows Server 2003, Look here: Turn off Shutdown Event Tracker  ]

1. Start...Run...Open: type: gpedit.msc

clip_image002

2. Of course...

image

3. Find: Local Computer Policy, Computer Configuration, Administrative Templates, System:

4. Select: Display Shutdown Event Tracker [Note: It's "Not Configured" by default.]

image

5. Double Click it and select the Disable radio button.

image 

Result: Here's what we want...

image

Aug 13

It's already mid-August and I just finished a round of BlogEngine.NET updates to take advantage of the new features in 1.4.5.x.  For a lot of folks, the need to Blog is what makes this platform so valuable.  But my clients, and my own interests also include adding Extensions and Advertising.  Now that there's  a Text box Widget, I can add simple ads like an Amazon link, Google AdSense, and affiliate links right in the Widget Zone without any special code.  Maybe this can be improved to target this medium, but I have to admit, if it works, I'm going to use it as is.  But there are a few things I'd like to see sooner than later.

Multiple Blog Support

What if I had 15 Blogs on different topics and some of them included overlapping authors?  I would like to support this configuration with One code base, One server or service layer, connecting to a Single SQL database or SQL Server farm.  I know I'd want this because I want it now and I have 8 Blogs, with 8 Web Apps, 4 AppPools, and 8 sets of XML Data.

SQL Server Express wouldn't cut it since my server started running into resource issues.  Not because of SQL Server but because I need 8 databases the way this configuration is setup.  Even if I upgrade my server (or hosting platform) to allow for more capacity, it doesn't scale.  Also, I will spend more time maintaining Blogs than writing for them.  So more Blogs = Less Blogging.  That's not a positive goal for me. Frown

See BlogEngine.NET on CodePlex: Multiple blogs in one BlogEngine.NET instance

I'm following the instructions from "Setting up BlogEngine.NET 1.4 to use SQL Server" so I can review the Provider and see if this seems practical.  I'll have to report back and add on here when complete.

Advertising the manual way

Anyone can now use a BlogEngine.NET 1.4.5 compatible theme and add a Text Box widget to the Widget Zone.  Then you can place and ad within, so long as it fits the box cleanly.  Don't forget colors, borders, iframe constraints., etc.  But this is still very clean compared with the alternative.

Using AdsenseInjector should place an AdSense ad within each blog post. I'm having problems when more than one AdSense block is configured on a page.  I still need to debug my specific issues, but it may stem from the fact that I messed with the Master file in the theme to place AdSense "elegantly" where I wanted it...of course this was just for testing the theory.  So, AdsenseInjector is a good start so I can't knock it.  It's certainly something I thought about but did no think through so now I have the benefit of someone else's labor.  However, I still would like to get it to work along side other Ads on my page.

Hacking various themes to produce Ad Friendly pages or posts may be the only way to get what I need.  Another way of looking at this could be to use the Widget or Webpart approach to building and organizing themes.

This was merely an exercise in describing what one blogger needs, but at the same time, setting in motion my attempts to achieve this and report back my R&D results.

Jul 20

I'd really like to see some more BlogEngine.NET themes take advantage of the new WidgetZone and cool features of version 1.4.  To that end, I wanted to see how difficult it would be to do this myself.  As a .NET architect and developer I haven't found myself doing a lot of css and UI interface work recently, but figured if I can do BizTalk, SharePoint, EntLib, SQL, WinForms and even ASP.NET development, HTML and css might be possible.  Besides, I'm only adding on to what other artists and geniuses have already done.

Here is my first attempt at modifying an existing BLogEngine.NET 1.3 theme to handle 1.4 functionality.  I went after one of my favorites: MWRT-002.

This is my update for BlogEngine.NET 1.4: MWRT-002-14.zip (23.24 kb)

Please critique, and let me know if you made any improvements that I had missed.  I'll be working on a few really nice themes from various locations over the next several weeks including one I'll be using on this site.  I'll try to show an example site soon.

Tags: | |

About the Author

BizTron BizTron
(aka Dave Petronis)
"Famous" systems architect and software developer, author, and "future President of the United States." View David Petronis's profile on LinkedIn
E-mail me Send mail

Banner
Compusa (Systemax, Inc.)

Calendar

<<  November 2008  >>
MoTuWeThFrSaSu
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

View posts in large calendar