Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Win Forms App Architecture

There are plenty of application examples that give you a good idea of how you should design your app, I can't find any Win Form apps that would give me an outline of some of the best practices, such as where I should store my database connection string etc.

Anyone know of any good examples?

Sunday, September 22, 2002

"where I should store my database connection string"

Like ASP.NET's web.config (where most people would store their ConnectionString), EXE applications can have a config file called "MyApp.exe.config" with an <appSettings> section where you could store it. In VS.NET create a file called "app.config" in your project and it gets copied and renamed to your build directory automatically.

If you want user-specific settings then the WinForms' Application.UserAppDataPath gets you to the logged in user's profile folder (specifically "Documents and Settings\<UserName>\Application Data\<CompanyName>\<AppName>\<versinNo>") where you can put whatever you like: e.g. serialise a "Settings" class; save an XmlDocument or DataSet... or whatever.

A WinForms "evangelist's" site and articles worth looking out for are those of Chris Sells ( ) -- he, and a bunch of others are also working on a set of libraries for WinForms called Genghis which are looking very useful.

Monday, September 23, 2002

One "best practice" I've learned from experience -- don't assume that your EXE will have write permission on its own directory -- in typical secure NT/2K/XP installations it won't.

Joel Spolsky
Monday, September 23, 2002

If you have even more restricted permissions (code running from the Net), you should look at Isolated storage.  isolated storage allows your assembly or assembly/user store data on the filesystem, without needing the standard file permissions to write.  Sometime a user will have access to write, but your program will not.

Michael Giagnocavo
Monday, September 23, 2002

There is an interesting article on MSDN, by Chris Sells (yes is worth a visit too!) about using Windows Forms as dumb clients, which access web services.

Article: State Sanity Using Smart Clients

In relation to validation, the technique I have used for client-side validation is the use of a thing called "broken rules" (have a look at any of the professional business objects for VB books by Rocky Lhotka @ Wrox).  This approach to validation means that it can be used both in the UI and the middle tier.  You could just defer validation to the middle tier, but if this is over a slow connection such as the Internet, your users may get a little annoyed by having to wait for a response from the server just to tell them that the data they have input is invalid!

Tim Riley
Wednesday, September 25, 2002

*  Recent Topics

*  Fog Creek Home