Tip of the day: Splitting a string when encountering whitespace

In .NET the string class has a Split method that splits the string at the separator character(s) that you specify. However, if you want to split the string at any instance of whitespace you don’t have to create a Split call that enumerates all those different types of whitespace… and there are actually quite a […]

Building messages in parallel

I recently saw some code where the developer was attempting to build up messages inside tasks that were being reported outside of the task. In a sequential system it is easy enough to do this. You have various options available to you, such as message += …; StringBuilder Streams However, in a parallel system these […]

Parallel Tasks and the HttpContext

A few days ago I spotted a question on StackOverflow by someone trying to use a parallel loop in an ASP.NET application. It may have been an ASP.NET MVC application (I don’t recall) but the issue is the same. This person had some code in a parallel task that was using the HttpContext object. I […]

ASP.NET MVC – Server Side Validation

So far, we’ve built up a basic application and got some client side validation working. However, client side validation only goes so far. While it can prevent unnecessary trips to the server, it doesn’t prevent invalid data getting to the  server if JavaScript is turned off or if a user crafts a specific HTTP request […]

ASP.NET MVC 3 – Introduction to validation

In my previous post on MVC 3 I started a project to calculate a calorific intake required to maintain a stable weight. In this post I’ll extent that to add some validation to the inputs. At the moment, since there is no validation, the use can just submit the input as it is with the […]

Starting an ASP.NET MVC 3 application

In this post, I’m going to show the basics of starting an application with ASP.NET MVC 3. The demo application will be a simple calorie counter that takes in a number of values from the user that is then used to calculate the calorific intake. The original calculation can be found here here: How many […]

Custom error pages and error handling in ASP.NET MVC 3

In ASP.NET MVC 3 a new bit of code appeared in the global.asax.cs file: public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } The above method is called from the Application_Start() method. Out of the box, what this does is set up a global filter for handling errors. You can still attribute controller methods or […]

Tip of the day #22: Obtaining all subdirectories recursively

This is an example of how to obtain a list of all subdirectories using a recursive method with the .NET Framework. public static List<DirectoryInfo> GetSubdirectories(DirectoryInfo directory) { // Set up the result of the method.List<DirectoryInfo> result = new List<DirectoryInfo>(); // Attempt to get a list of immediate child directories from the directory // that was […]