How do I put the settings, like server name, file names, etc, for my code in a separate text or ini file?
Printable View
How do I put the settings, like server name, file names, etc, for my code in a separate text or ini file?
Use a FileStream to write them to a text file.
Use a different FileStream to read the text file at Load and assign the values.
Your question's a little vague, so I can't offer more than that.
Simplest option:
Set up your settings file like this
use the following code to parse the stringsCode:value0
value1
value2
INI files are not supported by the framework because the creators want you to use XML. You can have a look a XML based settings here. There are also very simple classes built to support INI files if you are more familiar with those. I recommend this one. If I wasn't clear/missed something, let me know.Code:string temp;
string[] values;
TextReader tr = new StreamReader("Settings.ini");
temp = tr.ReadToEnd();
Console.WriteLine(temp);
values = temp.Split(Convert.ToChar(Environment.NewLine));
string setting0 = values[0];
string setting1 = values[1];
string setting2 = values[2];
EDIT: I recommend using the INI class
Use a Settings file!
In Visual Studio 2010:
Project->Add new item->Settings File
Read about user (variable) and application (constant) settings to decide which one you need.
You should be able to read and write your settings by accessing something like:
yourVariable = <projectNamespace>.Properties.<settingsFilename>.Default.<settingName>;