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.

Sep 03

From: TVUG President, Griff Townsend:

Sorry for the delay in getting this out: things always seem to get hectic around the time to put announcements out, and this month was no exception. With that said, I've spoken with this month's presenter (in the mirror), and he is ready to go.
Using the Entity Framework in .Net 3.5 SP1


Speaker: Griffith Townsend, MCP.Net, MCSE
When: Tuesday September 8th, 2008 - 6:30-9PM
Where: VersaTrans Solutions, Latham, NY


When developing multi-tiered applications, it’s not uncommon that to encounter code and architectural “noise” where a developer is forced to shift languages between the business logic layer and the data layer. The preference of many developers is the use of tools (typically Object Relational Mapping solutions) to abstract the database-specific aspects of the data layer into objects usable by the upper layers by object-oriented programming languages.

Microsoft’s long awaited Entity Framework (EF) is one approach to raise the level of abstraction in complex applications, separating the logical object schema from the underlying data store. EF allows developers a lot of flexibility in creating and mapping database entities, relationships, functions, and procedures into either direct class translations or custom business entities.

In this presentation, Griff Townsend introduces us to the Entity Framework as of its initial release in SP1, providing an architectural overview of EF, while also extending it into a working Data Layer. The presentation will also cover:

  • Building your first EF model
  • Using Stored Procedures and customizing business objects in the EF model
  • Extending the Framework to support more robust data access
  • LINQ to EF vs. LINQ to SQL
  • Sharing Entities between layers


Bio: Griff Townsend is a Senior Software Engineer for 6N Systems and the President of the Tech Valley .Net Users Group. In addition to over 14 years of web- and windows- development experience in Central and Upstate New York, he has also taught Software Development for Syracuse University and ITT Tech. He is a Microsoft Certified Developer in .Net, as well as a Microsoft Certified Systems Engineer. He's starting to blog these days, too.

Aug 19

clip_image001

A simple way to adjust or tweak a theme to your liking can be as simple as a few lines of css code in styles.css.  I made a couple very minor changes to achieve the affect of a new background color, content on the right when it was always on the left, and a font color change to go along with the background better.  This is what it looked like:

/* I replace the Standard body formatting:
body {
    background-color: #F1F1F1;
    color: #444444;
    font-family: Verdana;
    font-size: 11px;
    margin: 0 auto;
    width: 980px;
    position: relative;
}*/

/* With the following: */
body {
    background-color: #6699FF;
    color: #444444;
    font-family: Verdana;
    font-size: 11px;
    margin: 0 auto;
    width: 980px;
    position: relative;
}

 

image

/* I replaced these lines:
#content {
    float: left;
    width: 70%;
}

#sidepanel {
    float: right;
    width: 28%;
}

    With this...   */

#content {
    float: right;
    width: 70%;
}

#sidepanel {
    float: left;
    width: 28%;
}

 

/* I replaced these lines:
#header span {  font-weight: normal;   letter-spacing: 4px;

color: silver; margin: 0px; }

#header a { text-decoration: none;  color: white;  }

    With this...*/

#header span {  font-weight: normal;  letter-spacing: 4px;

color: #0000CC;  margin: 0px; }

#header a { text-decoration: none; color: #0000CC; }

Then there was the slight issue with the Date Time format on the Blog post.  This is an example of a minor inconvenience and a quick and dirty solution.  I'll describe an alternative approach later.

image

Notice the formatting for June 29, 2008.  This date can probably be localized, but today it's hard coded in PostView.aspx.

clip_image001[11]

Note: I changed

    <%=Post.DateCreated.ToString("d. MMMM yyyy HH:mm") %>

To...

    <%=Post.DateCreated.ToString("dddd, MMMM dd, yyyy hh:mm tt") %>

To get the following results:

image

Yeah, I know this wasn't earth shattering.  But the premise is simple.  If there's a theme you want to use, except for a couple small items, change them.  The next step from here is to create a BlogEngine.NET theme for version 1.4.5, using an open source.  The Widget Zone needs a little tweaking on some of the older 1.2 and 1.3 themes, but we've already done that once (It's just about time for a new theme and BlogEngine.NET 1.4).  I hope everyone tries that once so we can have a few more themes right away.

Here's the new theme.  I'll call it nonStandard since I'm not a marketing guy: nonStandard.zip (6.28 kb) .  Enjoy!!!

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

<<  December 2008  >>
MoTuWeThFrSaSu
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar