list files from a folder to a listbox RRS feed

  • Question

  • What I'm trying to do is to get the files I display from a folder to a listbox where each file will be displayed on a single row. Here's my code that I have and an image of the view

    private void LoadPlayable()
                string crrGame = MLHSetting.Default.currGame;
                string Spath = FullGamePath + @"\" + crrGame.Trim() + ".json";
                var cfg = gameInfo.LoadFromFile(Spath);
                DirectoryInfo playMissions = new DirectoryInfo(cfg.currPathString.Trim());
                foreach(FileInfo Files in playMissions.GetFiles("*." + cfg.missionnext))
                    m_Playable.Items.Add(Files.Name + Environment.NewLine);

    Here's what the code displays in the listbox. I just need it to display one file on one row. Delta Force Barracks Starfire Software

    Wednesday, March 27, 2019 9:02 AM


  • Hello,

    Can you indicate what the problem is?

    Here is a simple example

    namespace WindowsFormsApp2
        public partial class Form1 : Form
            public Form1()
            private void button1_Click(object sender, EventArgs e)
                var folderName = "C:\\Data";
                var results = Directory
                    .GetFiles(folderName, "*.xlsx")
                    .Select(file => Path.GetFileName(file))

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Wednesday, March 27, 2019 9:55 AM