A common problem I find when dealing with dates is when parsing a string to save in Sql Server. By default, the DateTime.Parse() method assumes that dates given to it are in US format. In order to get it to process a non-US format date, such as the UK dd/mm/yyyy format, we need to pass it the appropriate “culture” information, like so:

// we need to have imported System.Globalization
using System.Globalization;

// fetch the en-GB culture
CultureInfo ukCulture = new CultureInfo(“en-GB”);
// pass the DateTimeFormat information to DateTime.Parse
DateTime myDateTime = DateTime.Parse(“18/09/2004”,ukCulture.DateTimeFormat);

Once converted, you can then call things like  myDateTime.ToShortDateString() and actually get the format you expect – nice!


Migration to ASP.NET 2.0 breaks Crystal Reports

Crystal Reports

If you have an application using Crystal Reports and are migrating from VS .NET 2003 and VS 2005, or deploying your website from your development machine to the web server, a common problem that may arise is the following:

Could not load file or assembly ‘CrystalDecisions.ReportAppServer.CommLayer, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692fbea5521e1304’ or one of its dependencies. The system cannot find the file specified.

To solve this problem you must copy the following file on the server, and run the installer.

C:Program FilesMicrosoft Visual Studio 8SDKv2.0BootStrapperPackagesCrystalReportsCRRedist2005_x86.msi

This will put the missing packages on your web server thus be able to run crystal reports.