Reading files from application path may be one of key requirement of any application. Actually we can place many place you love to have, on a installation machine there can be restriction as well.
Like wise in a Windows system, installer may want to put apps and other files to Programfiles. This folder intended to work with executable,configuration files etc. You can’t programmatically create new folder or files in Programfiles folder, which may require some admin rights. So where we kept those documents and other data ?
It is wise to store such files on Application data folder or even on your Document folder. For reports and other stuffs Document folder is enough.
Access Special Folders
We can use the Enironment.SpecialFolder to access the App data and Documents and also can fetch path to those folders using GetFolderPath method of Environment class.
As a C# programmer, you may have used Back Color property for changing the color of the background for control as well as Windows form. You can also found that this not works with MDI Parent form.
MDI is the container for child forms or control, actually, it’s inherited from the panel [leave it no…lol].
Ok, all you want to repaint all the controls in it, even though there are no controls were placed, think about the inherited panel. All we have to do is try to cast every control as MDIClient and loop through it and change the color as follows
// Loop through all of the form's controls looking
// for the control of type MdiClient.
foreach (Control ctl in this.Controls)
// Attempt to cast the control to type MdiClient.
ctlMDI = (MdiClient)ctl;
// Set the BackColor of the MdiClient control.
ctlMDI.BackColor = Color.Gold;
catch (InvalidCastException exc)
// Catch and ignore the error if casting failed.
As we know stringsare a group of characters, usually composed of letters, numerals and special symbols etc. C# string type is immutable object, i.e, they can be created once, after that they can’t be modified.
Usually you may argue that it is a non sense, I am talking about. Let’s consider the following line of code
string str=” Some string”
str+=” Some other string”
Here firstly we created string variable str and add some initial string value and trying to add new string “Some other string” with the old one. Even Though there is + operator appeared after the variable, the string variable can’t be modified, instead C# will create a new string by combining the both strings. As a result more and more memory occupied.
Build mutable strings with StringBuilder
This problem can be simply fixed with in built C# class StringBuilder which is mutable object. Following example will clarify the idea. Create a console application which will execute a series of sample string for a specific times, say 1000.
Open the Diagnostic Tool in Visual Studio 2013/15 to find out memory usage. As the program get more complex you can find out that StringBuilder uses less memory than immutable string. StringBuilder also come with