Monthly Archives: September 2008
BlogEngine Maintenance
One thing I have found frustrating about the BlogEngine, when you are developing is I have to go on the the server to recycle the application pool if I need to refresh the object loaded in memory.
In addition I wanted a way to find out how may posts, pages and files the BlogEngine held in the application. Also find out the amout of hard disc space they used would be useful.
So I went ahead and wrote a Maintenance section
Installation is quite simple copy the admin/Maintenance folder in to the admin/maintenance folder.
Ammend the web.sitemap to include the maintenance
<siteMapNode url="~/admin/Pages/Maintenance/" title="Maintenance" description="" roles="administrators"/>
When you login as an administrator you will find the maintenance section appear.
Web 3.0
Speed up the Copy process on Windows Vista
Cancel some of Windows Vista Effects

1. Open Control Panel.
2. Click on ‘System and Maintenance’.
3. Click “Performance Information and Tools”.
4. Click “Adjust Visual Effects”.
Remove Tablet Feature
How do you convert a string into an enum?
I've come across the situation on a number of occasions when coding where I've wanted to convert from a string to an enum.
Here is one of those methods that you can never find when you're looking for it, but once discovered it seems blindingly obvious:
object Enum.Parse(System.Type enumType, string value, bool ignoreCase);
So you can write the following kind of code:
enum Colour
{
Red,
Green,
Blue
}
// …
Colour c = (Colour) Enum.Parse(typeof(Colour), "Red", true);
Console.WriteLine("Colour Value: {0}", c.ToString());
// Picking an invalid colour throws an ArgumentException. To
// avoid this, call Enum.IsDefined() first, as follows:
string nonColour = "Polkadot";
if (Enum.IsDefined(typeof(Colour), nonColour))
c = (Colour) Enum.Parse(typeof(Colour), nonColour, true);
else
MessageBox.Show("Uh oh!");
Footnote: interestingly, whilst writing this up I noticed that Enum.IsDefined() doesn’t offer the ignoreCase parameter. If you don’t know whether the casing is right, it seems the only way to do the conversion is using the Parse method and catching the ArgumentException. That's not ideal, since it runs a lot slower. I wonder if this is a loophole in the design?
DateTime Format
I’m always searching the internet for DateTime formats, so I’ve placed them in my Blog so I’ll also know where I can find them
DateTime Format Specifiers
Below lists the valid format specifiers supported by the Format
method on theDateTime
type (see System.IFormattable
).
DateTime Format Specifiers
Specifier | String Result |
d | MM/dd/yyyy |
D | dddd, MMMM dd, yyyy |
f | dddd, MMMM dd, yyyy HH:mm |
F | dddd, MMMM dd, yyyy HH:mm:ss |
g | MM/dd/yyyy HH:mm |
G | MM/dd/yyyy HH:mm:ss |
m, M | MMMM dd |
r, R | Ddd, dd MMM yyyy HH’:’mm’:’ss ‘GMT’ |
s | yyyy-MM-dd HH:mm:ss |
S | yyyy-MM-dd HH:mm:ss GMT |
t | HH:mm |
T | HH:mm:ss |
u | yyyy-MM-dd HH:mm:ss |
U | dddd, MMMM dd, yyyy HH:mm:ss |
y, Y | MMMM, yyyy |
Here’s an example that uses these custom format specifiers on a DateTime
value:
using System;class TestDateTimeFormats {static void Main( ) {DateTime dt = new DateTime(2000, 10, 11, 15, 32, 14);// Prints "2000-10-11T15:32:14"Console.WriteLine(dt.ToString( ));// Prints "Wednesday, October 11, 2000"Console.WriteLine("{0}", dt);// Prints "10/11/2000"Console.WriteLine("{0:d}", dt);// Prints "Wednesday, October 11, 2000"Console.WriteLine("{0:D}", dt);// Prints "Wednesday, October 11, 2000 3:32 PM"Console.WriteLine("{0:f}", dt);// Prints "Wednesday, October 11, 2000 3:32:14 PM"Console.WriteLine("{0:F}", dt);// Prints "10/11/2000 3:32 PM"Console.WriteLine("{0:g}", dt);// Prints "10/11/2000 3:32:14 PM"Console.WriteLine("{0:G}", dt);// Prints "October 11"Console.WriteLine("{0:m}", dt);// Prints "October 11"Console.WriteLine("{0:M}", dt);// Prints "Wed, 11 Oct 2000 22:32:14 GMT"Console.WriteLine("{0:r}", dt);// Prints "Wed, 11 Oct 2000 22:32:14 GMT"Console.WriteLine("{0:R}", dt);// Prints "3:32 PM"Console.WriteLine("{0:t}", dt);// Prints "3:32:14 PM"Console.WriteLine("{0:T}", dt);// Prints "2000-10-11 22:32:14Z"Console.WriteLine("{0:u}", dt);// Prints "Wednesday, October 11, 2000 10:32:14 PM"Console.WriteLine("{0:U}", dt);// Prints "October, 2000"Console.WriteLine("{0:y}", dt);// Prints "October, 2000"Console.WriteLine("{0:Y}", dt);// Prints "Wednesday the 11 day of October in the year 2000"Console.WriteLine("{0:dddd 'the' d 'day of' MMMM 'in the year' yyyy}", dt);}}
Windows and .NET incompatability
There are some things to consider when using these default formatters in an international environment.
Console.WriteLine("{0:t}", dt); // Prints "3:32:14 PM"Console.WriteLine("{0:T}", dt); // Prints "2000-10-11 22:32:14Z"
The difference between {0:t}
and {0:T}
has to be taken into account. This difference is due to the fact that .NET has two date time representations—Long ( T )
and Short ( t )
—while Windows uses only the Long
notation.
So, if a user changes the Regional Settings in Windows only the Long
notation will follow this change in .NET. This means that the programmer has to perform his own formatting—and not use the default formatters—if he wants to follow the users settings—not something a programmer should expect.
It’s worth check out SteveX Blog on String Formats
Software Requirements
The Swing
Just loved this cartoon, they always say a picture says a thousand words
Embed Picasa slideshows into BlogEngine.net
I was having a problem embedding a slide show from Picasa into my BlogEngine.net editor. Basically, the editor kept stripping the embed html. The trick is to edit \admin\tinyMCE.ascx file. You need to modify the extended_valid_elements entry. Apparently this is used to define valid html tags for the tinyMCE editor. Here are my additions in red:
extended_valid_elements : "hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],
script[charset|defer|language|src|type],code,iframe[src|width|height|frameborder|name|style],
embed[type|src|width|height|flashvars|pluginspage]",
Have fun!
Visual Studio, which version?
What version of Visual Studio is the most current?
Depending on what you are using and which application you are modifing the following are the latest releases of Visual Studio:
- Latest build is 9782 and this corresponds to Visual Studio 6.0 SP6.
- Version 7.1.6030. This corresponds to VS2003 SP1 and is a MANDATORY install. If you don't have it install it now.
- Version 8.0.50727,762 (SP). This corresponds to VS2005 SP1 and is a MANDATORY install. If you don't have it install it now. It can also take over an hour to install.
- Version 9.0.21022.8 RTM. This corresponds to the RTM release so if you have VS2008 you have this build.