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 504259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:28:42+00:00 2026-05-13T06:28:42+00:00

What I have is a comboBox being populated from a code: InitializeComponent(); DirectoryInfo dinfo

  • 0

What I have is a comboBox being populated from a code:

InitializeComponent();
        DirectoryInfo dinfo = new DirectoryInfo(@"K:\ases");
        FileInfo[] Files = dinfo.GetFiles("*.ssi", SearchOption.AllDirectories);
        foreach (FileInfo file in Files)
        {
            comboBox1.Items.Add(file.Name);
        }

Then i’m trying to ReadAllText from that selected item.

    string contents = File.ReadAllText(comboBox1.Text);

When executed, it tries to read the file from the locale path, and of course the file isnt there. I also can’t set the working directory because the comoboBox is populated from a huge range of subdirectories. How do I get the working directory of the item selected in the combobox WITHOUT expossing the whole directory path to the user?

Any help always welcomed

I thought i saw a few answers with someone suggesting private and hiding things in a combox box, where those suggestions taken down. is there a way to keep the full file info in the combobox and only display the file name?

  • 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-13T06:28:42+00:00Added an answer on May 13, 2026 at 6:28 am

    There are several different ways to accomplish this, but the absolute easiest would be to store the directory path in an instance variable (we’ll call it directoryPath) and use System.IO.Path.Combine() to reconstruct the path:

    (some code eliminated for brevity)

    public class Form1 : Form
    {
        private string directoryPath;
    
        public Form1()
        {
            InitializeComponent();
            DirectoryInfo dinfo = new DirectoryInfo(@"K:\ases");
            FileInfo[] Files = dinfo.GetFiles("*.ssi", SearchOption.AllDirectories);
            foreach (FileInfo file in Files)
            {
                comboBox1.Items.Add(file.Name);
            }
    
            directoryPath = dinfo.FullName;
        }
    
        private void YourFunction()
        {
            string contents = File.ReadAllText(System.IO.Path.Combine(directoryPath, comboBox1.Text);
        }
    }
    

    You could also try adding the FileInfo to the ComboBox rather than the file’s name and use SelectedItem rather than Text:

        InitializeComponent();
    
        DirectoryInfo dinfo = new DirectoryInfo(@"K:\ases");
        comboBox1.DataSource = dinfo.GetFiles("*.ssi", SearchOption.AllDirectories);
    
        comboBox1.DisplayMember = "Name";
    

    Then you can do this to retrieve the file:

    FileInfo file = (FileInfo)comboBox1.SelectedItem;
    
    string contents = File.ReadAllText(file.FullName);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 236k
  • Answers 236k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I appreciate all the helpful responses. I tried most of… May 13, 2026 at 6:28 am
  • Editorial Team
    Editorial Team added an answer Why don't you change your production.rb config to match the… May 13, 2026 at 6:28 am
  • Editorial Team
    Editorial Team added an answer Found the problem. We had a script in the parent… May 13, 2026 at 6:28 am

Related Questions

Scenario: I have a list table being populated from a combobox. That list table
I have a radajaxpanel that is populated with the selected item from a combobox
I have a listbox being populated from a combo box. What i need to
Urgh, I have spent the last couple of hours on this now. I normally
We have a layered application, or at least is in the process of transitioning

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.