Sunday, August 27, 2006

Application Settings for Windows Forms .NET 2.0

Application Settings in .NET 2.0 allows to a developer to concentrate on real tasks, and not re-implement settings handling for every new application.

I did not have any experience with Application Settings, but with help of Visual Studio (it automatically generates all required stuff), it took five minute to add settings to an application.

The only problem was to get settings from previous version(s) of application. So it was time to load MSDN and read the documentation :)

ApplicationSettingsBase class has almost everything for the task: migration should be performed right after the settings was loaded, so it can be performed in handler of SettingsLoaded event. And Upgrade method allows to automatically migrate settings.

So all you need to do is to add a special boolean setting IsFirstRun with default value as true, and in SettingsLoaded handler call Upgrade if IsFirstRun is false.

Here is a snippet from Settings.cs (it should be generated by Visual Studio):



internal sealed partial class Settings
{
 public Settings()
 {
  SettingsLoaded += new SettingsLoadedEventHandler(Settings_SettingsLoaded);
 }
 
 void Settings_SettingsLoaded(object sender, SettingsLoadedEventArgs e)
 {
  if (IsFirstRun)
  {
   Upgrade();
   IsFirstRun = false;
  }
 }
}

Labels: ,

Saturday, August 26, 2006

Utility to convert ASP.NET sitemap to Google sitemap

Google sitemaps is a way for webmaster to notify Google about site changes. A website created with ASP.NET 2.0 also could contain a sitemap with navigation structure of the site. And, basically, both sitemaps are containing the same urls, but in different formats.

I needed a tool to generate Google sitemap from ASP.NET sitemap. I searched for such utility, but did not find what I need, so I created one. The utility is open-sourced (BSD license). I registered project at both Google Code and SourceForge, but Subversion hosted at  Google Code. (BTW, do you know that SF.net now allows to use third-party SVN hosting?).

Download

Labels: , , , , ,

Tuesday, August 01, 2006

SelectedDate property of Calendar control (ASP.NET 2.0)

Another day, another trick...
Spent a while in attempts to select a specific date in ASP.NET Calendar control. And it appears SelectedDate property is ignoring assigned value if it's not a midnight of the day. Date property of DateTime class is useful for that.

Here is a snippet:

_calendar.SelectedDate = DateTime.Now.Date;

Labels: , ,