A place to put my code ramblings…

Pluralisation is the act of making a singular word to its plural equivilent. For example, baby should equal babies and student should equal students.

I was thinking how difficult this would be to do in code without asking users to type both singular and plural in.

So I have come up with the following function that should convert a given word into its plural equivilent. It should also take care of if a word is already plural. I have written both methods in C# and JavaScript below. There are few changes between them.

public string Pluralise(string word) {
if (word[word.Length - 1] == 's')
return word;

if (name[word.Length - 1] == 'y' && word[word.Length - 2] != 'e')
return word.Substring(0, word.Length - 1) + "ies";

return word + "s";


function Pluralise(word) {
if (word[word.length - 1] == 's')
return word;

if (word[word.length - 1] == 'y' && word[word.length - 2] != 'e')
return word.substring(0, word.length - 1) + "ies";

return name + "s";


You can approach this like:

string newSetting = txtSetting.Text;
Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection section = (AppSettingsSection)config.GetSection("appSettings");
section.Settings["AnAppSetting"].Value = newSetting;

Recently I have been using the ASP.net AJAX Toolkit and one of the best things about this toolkit is that the controls are compiled into one nice sized DLL.  This left me thinking, why don’t I create my own library of reusable usercontrols and compile them into a single DLL instead of including the seperate files together.
I found a nice tutorial on how to do this here.

Here is another tutorial I found that shows you how to create server controls that can be added to the toolbox here.


I have a text box that the user inputs a time like “22:30”. But I don’t want the page to postback unless the input is valid. This is where the RegularExpressionValidator comes in to play.

What is the RegularExpressionValidator?
Basically, it is a control that you add to the page just like a button or text box. When you declare it in markup it adds client side code that validates this control on the client side and will cancel the postback if it is not valid.

Here is the the code I used:

<asp:TextBox ID="txtStartTime" runat="server" />
<asp:RegularExpressionValidator ID="regexStartTime" ControlToValidate="txtStartTime"
     ValidationExpression="^([0-1][0-9]|[2][0-3]):([0-5][0-9])$" ErrorMessage="Input valid date" runat="server" />

As you can see, I have a text box declared and under it I have declared a RegularExpressionValidator. The attributes I have used are:
– ID = a unique id for the control on the page
– ControlToValidate = the id of the control to validate
– ValidationExpression = the regex to use to validate the input
– ErrorMessage = your custom error message if validation fails

The regex I used to validate a 24 hour time input (HH:MM) is:

This operation requires IIS integrated pipeline mode..

I was recieving this error in ASP.net.  The cause of the error was the following line:

Response.Headers.Add(“content-disposition”, “inline; filename=\”somefile.txt\””);


The workaround I used for this was to use the AddHeader method instead:

Response.AddHeader(“content-disposition”, “inline; filename=\”somfile.txt\””);

I’ve been playing around with ASP.NET AJAX recently and decided to try out a few controls in the AJAXControlToolKit and I received this message the first time I used the AsyncFileUpload control.


The solution was to include the following, somewhere on the same page as the AJAX control

<asp:ScriptManager ID=”ajaxScript” runat=”server”>