-
December 14th, 2011, 02:36 PM
#1
Text file settings
How do I put the settings, like server name, file names, etc, for my code in a separate text or ini file?
-
December 14th, 2011, 03:00 PM
#2
Re: Text file settings
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.
Code:
if (Issue.Resolved)
{
ThreadTools.Click();
MarkThreadResolved();
}
-
December 15th, 2011, 04:34 AM
#3
Re: Text file settings
Simplest option:
Set up your settings file like this
Code:
value0
value1
value2
use the following code to parse the strings
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];
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.
EDIT: I recommend using the INI class
Last edited by EdoSZ; December 15th, 2011 at 04:43 AM.
Reason: Added info
-
December 15th, 2011, 07:46 AM
#4
Re: Text file settings
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>;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|