Some useful code for windows application

Hi

In this post I am going to talk about some of the small but useful code used (or required) very commonly in the Windows application. 

To get the path to all the Important folders on the client machine, we need to use the System.Envirement namespace. We use the GetFolderPath and pass the value of type Environment.SpecialFolder. This way we can get the path to most of the important folders on the clients machine.

MessageBox.Show(Environment.GetFolderPath(Environment.SpecialFolder.Personal ) ); 
To get the path to the running exe we use the ExecutablePath property of the application class. We can also do this by using the following code.  
System.Reflection.Assembly.GetExecutingAssembly().Location
Many a time we also need to find the operating system the application is running on. This is also very simple to find. We use the Environment.OSVersion property for this purpose.
OperatingSystem os = Environment.OSVersion;
MessageBox.Show(os.Version.ToString());
MessageBox.Show(os.Platform.ToString());
Hope this helps
Thanks
Vikram

Share this post   Email it |  digg it! |  reddit! |  bookmark it!

Feedback

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 
Copyright © 2006 - 2009 Vikram Lakhotia