Click here to Skip to main content
15,066,064 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there a way to specify the folder and the file separately? Instead of specifying the complete path (C:\Path\app_path.txt\) I want to specify them separately (C:\Path\ + "app_path.txt").

C:\Path_app_path.txt\ is the main folder, there are several files stored there that I would like to open individually later.

What I have tried:

C#
{
    try
    {
        string text = File.ReadAllText("app_path.txt"); //Main Directory
        string config = File.ReadAllText(config + "/Settings.cfg"); //Main Directory + File I want to open
        TextView_Configs.Text = config;
    }
    catch (Exception ex)
    {

    }
}
Posted
Updated 3-May-21 2:20am

1 solution

You can't do this:
C#
string config = File.ReadAllText(config + "/Settings.cfg");
Since that line declares the variable config, you can't use it's value in the assignment as it doesn't have any value yet!

That won't even compile, and for good reason ...

Try this:
C#
string path = @"C:\Path\";
string file = "app_path.Text";
string fullPath = Path.Combine(path, file);
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900