Resolved Opening file from listbox

Katonas

Member
Joined
Sep 6, 2022
Messages
6
Programming Experience
Beginner
Hello
I have listbox which contains ini failes from directories. Now I want be able to read and open selected file from listbox, but im having trouble doing it now.
My code atm.
C#:
private void Form1_Load(object sender, EventArgs e)
{
    string rootdir = @"C:\Users\isaced1\Desktop\test";

    string[] files = Directory.GetFiles(rootdir, "*.ini", SearchOption.AllDirectories);
    //var folder = @"C:\Users\isaced1\Desktop\test\";
    //var txtFiles = Directory.GetFiles(files, "*.ini");
    Projects.Items.AddRange(files);

    var items = Projects.SelectedItems;
    foreach (var item in items)
    {
        string fileName = Projects.GetItemText(item);
        string fileContents = System.IO.File.ReadAllText(fileName);
        Process.Start(fileContents);
    }
}
 
Last edited by a moderator:
im having trouble doing it
What trouble? Explain in detail.

You say that you are working with INI files. What makes you think that you should be able to read the entire contents of an INI file and pass that to Process.Start? What are you expecting that file contents to be and what are you expecting to happen? Explain in detail.

Also, please don't post unformatted code snippets. They are hard to read. I'm sure you've used text editors before so formatting your post appropriately should not be an issue.
 
What trouble? Explain in detail.

You say that you are working with INI files. What makes you think that you should be able to read the entire contents of an INI file and pass that to Process.Start? What are you expecting that file contents to be and what are you expecting to happen? Explain in detail.

Also, please don't post unformatted code snippets. They are hard to read. I'm sure you've used text editors before so formatting your post appropriately should not be an issue.
Yes my bad I actually just managed to do it myself and was about to delete thread.
 

Latest posts

Back
Top Bottom