Home > Guides > Programming > .NET and Windows Programming

Toggle Open Guide Table of ContentsGuide Contents

Close Table of ContentsGuide Contents

Close Table of Contents

Managing Windows Forms Applications

Last updated Jul 16, 2004.

The System.Windows.Forms.Application class provides methods and properties that allow you to manage Windows Forms applications and obtain information about the application's runtime environment.

Data Paths and Registry Keys

Whereas the System.Environment class contains properties and methods that provide information about the system in general and is available from all types of .NET programs, Application class is available only to Windows Forms applications and the information provide applies specifically to the executing program. For example, if you call the System.Environment.GetFolderPath method to obtain the common application data path (System.Environment.SpecialFolder.CommonApplicationData), the returned value will be the base directory for all common application data. A typical value for would be "C:\Documents and Settings\All Users\Application Data". System.Windows.Forms.Application.CommonAppDataPath, on the other hand, returns the directory containing common data for the specific application. For example, in a Windows Forms program called "formsInfo", the returned value would be "C:\Documents and Settings\All Users\Application Data\Hackers, Inc.\formsInfo\1.0.5.200". In this path name, "Hackers, Inc.", "formsInfo", and the version number (1.0.5.200) are the values that are entered in the application's AssemblyInfo.cs (AssemblyInfo.vb) file for the AssemblyCompany, AssemblyProduct, and AssemblyVersion attributes.

The Application class contains the following path and registry entry properties, all of which follow the same naming schema: company\product\version:

  • CommonAppDataPath gets the path for application data that is shared among all users of the current application.

  • CommonAppDataRegistry gets the registry key for application data that is shared among all users of the application.

  • LocalUserAppDataPath gets the path where the local, non-roaming user will store data for this application.

  • UserAppDataPath gets the path to store application data for this user that will be available in the user's roaming profile.

  • UserAppDataRegistry gets the registry key for user-specific application data.

Two other paths will be of interest to some programs: ExecutablePath and StartupPath. ExecutablePath gets the fully-qualified path name of the executing program. For example, "D:\MyProgram\bin\Debug\MyProgram.exe". StartupPath returns the path of the directory that contains the executable program. Given the previous example, that would be "D:\MyProgram\bin\Debug". StartupPath is poorly named, as it could be confused with the program's initial working directory, a value that you can set in the shortcut properties dialog box.

Discussions

Copies of the array?
Posted Dec 23, 2008 03:40 PM by luige21
1 Replies
Hi
Posted Dec 5, 2008 05:10 AM by ajay2000bhushan
2 Replies
You have no clue.
Posted Jun 10, 2008 03:28 PM by theinternetmaster
1 Replies

Make a New Comment

You must log in in order to post a comment.

Related Resources

Jim Mischel"Highly unlikely" does not mean "impossible"
By Jim MischelJuly 18, 2009 No Comments

One of my programs crashed the other day in a very unexpected place.  A call to System.Threading.ConcurrentQueue.TryDequeue (from the Parallel Extensions to .NET) resulted in an OverflowException being thrown.  Investigation revealed a pretty serious bug in the System.Random constructor.

It's Here; Put Away Your Pre-Conceptions on What an OS Must Be: Part II
By John TraenkenschuhMay 24, 2009 No Comments

In the last blog in this series, Traenk relates his first experiences with computers and with coding.  But now, some years have passed. . .

It's Here; Put Away Your Pre-Conceptions on What an OS Must Be: Part I
By John TraenkenschuhMay 24, 2009 No Comments

Traenk relates his past experience with Operating Systems that goes back 25 years, ok, more than that but he ain't tellin'

See More Blogs

Informit Network