CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2011
    Posts
    38

    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?

  2. #2
    Join Date
    Dec 2008
    Posts
    144

    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();
    }

  3. #3
    Join Date
    Dec 2011
    Posts
    10

    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

  4. #4
    Join Date
    Jun 2011
    Location
    Buenos Aires, Argentina
    Posts
    130

    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
  •  





Click Here to Expand Forum to Full Width

Featured