Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6152877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:59:46+00:00 2026-05-23T19:59:46+00:00

I have added 3 text file resources to an app and am trying to

  • 0

I have added 3 text file resources to an app and am trying to read from them but I just can’t seem to hack it. I’ve tried using a filestream and have just tried using ResourceReader and I’ve tried a combination of the 2 but no luck , any ideas on how I could get started with this?

Oh yeah, the purpose of the resource files is to load values into combo boxes on form_load. I’ve decided to do it like that so the EU can add and remove vals as he/she sees fit.

If you think there are better (but still unobtrusive) ways of doing it then please do share.

Here’s what I`ve tried and failed with:

the Filestream approach, where TextFile1(to 3).txt is the resource text file, it dies quietly on the new FileStream() statement, with no exception thrown

    private void Scan_Form_Load(object sender, EventArgs e)
    {
        // read combo box values from textfile
        AddVals("TextFile1.txt",cmbBox1);
        AddVals("TextFile2.txt", cmbBox2);
        AddVals("TextFile3.txt", cmbBox3);


    }

    private void AddVals(string fileName,ComboBox thisBox)
    {
        using (FileStream repFs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
        {
            StreamReader strReader = new StreamReader(repFs);
            ArrayList aVals = new ArrayList();
            while (strReader.Peek() != -1)
            {
                aVals.Add(strReader.ReadLine());
            }

            foreach (object val in aVals)
            {
                thisBox.Items.Add(val.ToString());
            }
        }
    }

Then the ResourceReader + FileStream approach, same problem , the main difference being that I just call the filename string in the non-fs approach instead of opening the stream:

               private void AddVals(string fileName, ComboBox thisBox)
        { 
        using (FileStream fs = new FileStream(fileName, FileMode.Open))
        {
            IResourceReader reader = new ResourceReader(fs);
            IDictionaryEnumerator en = reader.GetEnumerator();
            while (en.MoveNext())
            {
                string val = en.Value.ToString();
                thisBox.Items.Add(val);
            }
            fs.Close();
            reader.Close();
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:59:47+00:00Added an answer on May 23, 2026 at 7:59 pm

    You can just place the info you want to store in the app.config file like so.
    It’s very easy to set up if you just right click on the project in the solution explorer and go to the settings tab.

    The user could technically edit the app.config file directly but you could also give the user a form to edit it on.

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
            <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
                <section name="CSharpWindowsFormsApplication1.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
            </sectionGroup>
        </configSections>
        <applicationSettings>
            <CSharpWindowsFormsApplication1.Properties.Settings>
                <setting name="comboBox1" serializeAs="Xml">
                    <value>
                        <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                            <string>choice1</string>
                            <string>choice2</string>
                            <string>choice3</string>
                            <string>choice4</string>
                            <string>choice5</string>
                        </ArrayOfString>
                    </value>
                </setting>
                <setting name="comboBox2" serializeAs="Xml">
                    <value>
                        <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                            <string>choice1</string>
                            <string>choice2</string>
                            <string>choice3</string>
                            <string>choice4</string>
                            <string>choice5</string>
                        </ArrayOfString>
                    </value>
                </setting>
                <setting name="comboBox3" serializeAs="Xml">
                    <value>
                        <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                            <string>choice1</string>
                            <string>choice2</string>
                            <string>choice3</string>
                            <string>choice4</string>
                            <string>choice5</string>
                        </ArrayOfString>
                    </value>
                </setting>
            </CSharpWindowsFormsApplication1.Properties.Settings>
        </applicationSettings>
    </configuration>
    

    EDIT: In case it’s not apparent, those are System.Collections.Specialized.StringCollection type settings.

    and…

            private void Scan_Form_Load(object sender, EventArgs e)
        {
            // read combo box values from textfile
            comboBox1.DataSource = Properties.Settings.Default.comboBox1;
            comboBox2.DataSource = Properties.Settings.Default.comboBox2;
            comboBox3.DataSource = Properties.Settings.Default.comboBox3;
        }
    

    EDIT:
    Like I said at the top, right click on the project in the solution explorer and go to the settings tab. Once you’re in there:

    1. Create a setting with whatever name you wish, “comboBox1” for
      example.
    2. Change it’s type to System.Collections.Specialized.StringCollection
    3. Change the Scope to be whatever you like. (You can use this to set if the setting applies to a given user or the whole app)
    4. Click in the value editor and click the elipsis […] button at the right side of the line.
    5. Add an option that you want on each line.
    6. Repeat as needed.

    Visual studio will take care of how to format it all in the config file and set up everything it needs to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a html template that I want to retrieve from the resources file
I have a text file added as a raw resource. The text file contains
I have added an extra field Specification in Catalog->Product->Data tab. This text is stored
I am making text editor in netbeans and have added jMenuItems called Copy,Cut &
I have a tableview with a navigation bar at the top. I've added text
I have a View where some input text to be added dynamica using jquery,
I have added an HTML file to my solution in VS2010. How do you
I have just changed my WPF application from .Net3.5 to .Net4. Doing this caused
I am trying to log the output of tests to a text file. I
I have a text file with two non-ascii bytes (0xFF and 0xFE): ??58832520.3,ABC 348384,DEF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.