Dave Transom's CSharpVitamins

An occasional blog about C#, Javascript and Web Development

What's wrong with Request.Headers["Accept-Encoding"].Contains("gzip")?

posted on 6 Jul 2008

This post has been brewing for a little while. It stems from an inconsistency I've seen in code posted here and there over the web . Quite specifically this happens often when trying to detect which Accept-Encoding a browser can accept, so a GZIP or DEFLATE filter can be used to compress the content. The Offending Code The code in question goes something like this: What's wrong with it? It seems to be pretty standard and widely in use. Well, consider the following… » more

Drinking from the, erm... garden hose?

posted on 6 Feb 2008

So, I finally signed up to dotnetkicks , and submitted my first story - it just happened to be my own " Build Providers: Strongly typed page urls in ASP.NET " post - which is an interesting take on improving productivity by using a build provider to create a strongly typed hierarchy of the files in your Visual Studio project, to avoid mis-typing page locations and improving intellisense. On the same page It turns out that Kirill Chilingarashvili was trying to solve the same… » more

Build Providers: Strongly typed page urls in ASP.NET

posted on 3 Feb 2008

I'm a fan of strong typing in .NET as you gain compile time validation of code, Visual Studio Intellisense support, not to mention less mucking around with type conversion or dealing with (usually inconsistently) entering strings for page names and configuration setting keys inline. Visual Studio provides intellisense and some degree of validation for pages (i.e. urls) within a project when using Design Mode, but using those urls in code, e.g.. you're out of luck as there isn… » more

ShortGuid - A shorter and url friendly GUID class in C#

posted on 20 Dec 2007

Update 2019-11-22: Code for this post has been moved to GitHub with a NuGet Package now available. I like Mads Kristensen , he's often coming up with useful code snippets which he shares with the community AND he heads up the BlogEngine.NET project. He's produced the GuidEncoder helper class, which takes a standard guid like this: And shortens it to a smaller string like this: Which is a huge help if you happen to be using guids in your URL's. You can read his article… » more

Programmatically setting the SmtpClient pickup directory location at runtime

posted on 19 Dec 2007

In my last post on using an smtp pickup directory for ASP.NET development , I explained some of the reasons to use a pickup folder instead of an SMTP server during ASP.NET development. One of the caveats of that configuration is that you have to enter the full path of the folder you want to store the application's mail in. This is fine if you're working solo, or can agree on a common folder/path use amongst your colleagues but it reduces the instant portability of your… » more

Using an smtp pickup directory for ASP.NET development

posted on 28 Nov 2007

I don't know why this never occurred to me before, but using as the SmtpDeliveryMethod for sending email while developing ASP.NET websites is a very good idea. I was recently 'forced' to start using a mail pickup directory for development when I upgraded to Vista (yes I said upgraded) and found out that IIS7 doesn't ship with an SMTP Server . Many blog posts out there recommend using third party software like SmarterMail , Free SMTP Server or other cheap shareware… » more

The Smield: An unobtrusive javascript UI Helping Smart Field

posted on 14 May 2007

The 'smield', or sm art fi eld , is a useful little user interface widget written in javascript. It combines the values of other fields on the page to allow for easier input of repeated content. Based on some javascript configuration, the smield will insert an unordered list of label and radio button pairs under the target input field (of the smield). A few common examples might be: You have a list of customers. Some of those customers might be known by a their company… » more

Building an Age Class in C#

posted on 1 May 2007

It may seem like a fairly inconsequential idea since we already have the DateTime and TimeSpan structs. You can take two DateTime instances and easily calculate a TimeSpan. Once you have the TimeSpan, you can retrieve the Days property, divide that by 365 for the round about number of years and you're good to go. But wait, you can display that as an integer, or perhaps as a decimal for a bit more accuracy, but what if you want a human readable and understandable string like… » more

Filtering PropertyChanged events

posted on 30 Apr 2007

Recently, while working on a CMS project, I had the need to update a part of the UI if certain values of my business object changed. Basically, the scenario was that if the name of a page changed, the navigational sitemap should also update to reflect the change. The objects in our business library implement the INotifyPropertyChanged , so it's simple enough to subscribe to a event. But I only wanted to determine if a select few of the properties changed so that I could… » more

Out with Blogger. In with Subtext.

posted on 28 Apr 2007

Although only a new blogger myself, my choice for entry into this realm wasn't the best considering my background. I chose google's Blogger service to get started quickly and just get posting. It worked too, with practically no set up, I could start writing and the results were automatically published via FTP to my location of choice. Awesome. But by the second or third post, I found that I was becoming increasingly frustrated with the editor provided. Being a web developer… » more

The YUI Simple Controls for Shared Hosting (ASP.NET)

posted on 7 Mar 2007

With the release of Yahoo!'s shared hosting for YUI (Read their article: Serving YUI Files from Yahoo! Servers ) I thought I'd release a couple of ASP.NET server controls (and practices) I've found as a great helper. Firstly, I think YUI (and I say it yooey :) is a great library. It uses some tight OO patterns, and is headed by some of the key instigators in how we currently use javascript as a first class object oriented language. A couple of years ago I read Douglas… » more

Text Helper Utility Part 2: Separation of cased words

posted on 28 Feb 2007

Following yesterday's TextHelper.Coalesce post, I'd like to share another useful method for separating cased words i.e. PascalCase or camelCase. There are a few reasons you might want to do this. It's common place today to use it in Javascript for dealing to CSS styles and the like. The inspiration behind this one was to be able to display the members of an enumeration in a meaningful way to the user e.g. using Enum.GetNames to bind possible values to a drop down list… » more

Text Helper Utility Part 1: C# Coalesce

posted on 27 Feb 2007

I thought that I should start with something simple, yet useful, to get the blogging juices flowing. So I'm going to write about some of the utility and helper classes I deal with on a day to day basis; The TextHelper. TextHelper is static helper class containing useful methods for dealing with text and strings. Existing language functionality: The first method, and the one I use the most, is a spin off of the Transact-SQL COALESCE function. It adheres to the same… » more

I'm your host, Dave Transom

posted on 26 Jan 2007

It's been talked about for a long time, although only amongst colleagues and friends, but I finally have put some time into starting a blog. So here it is, my first blog post ever, that is if you ignore the blogesque style personal websites I started out with in the nineties, before 'blogging' came to, erm, fruition? Who am I? I've got to admit, I'm a nerd - I love programming , it's my profession and a hobby too, and it is maybe the reason this blog hasn't happened sooner… » more