1

I am trying to make a file path inside of the folder above the executable. For instance, I am wanting the variable TAGPATH to be the filepath to an executable in the folder C:\User\ApplicationFolder\tag_rw\tag_rw.exe while the application is in C:\User\ApplicationFolder\AppFiles. I want the application to be portable, meaning no matter the folder names it will retrieve the filepath of the application's executable then go to the parent folder and navigate into tag_rw\tag_rw.exe.

I basically want string TAGPATH = @"path_to_appfolder\\tag_rw\\tag_rw.exe"

Here is what I have tired so far (using the first answer How to navigate a few folders up? ):

  string appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
  string TAGPATH = System.IO.Path.GetFullPath(System.IO.Path.Combine(appPath, @"..\"));

I am getting a run-time error ArgumentException with the description URI formats are not supported.

Is there an easier/better way to go about this?

Thank you!

Community
  • 1
  • 1
NM24
  • 39
  • 6
  • If i did not misunderstand your question, you simply want get **parent directory**? – Lei Yang Dec 05 '16 at 01:25
  • Yes. Should have just said that instead of the long paragraph. It would also be nice to get the parent directory of the initial parent directory as well. – NM24 Dec 05 '16 at 01:29

2 Answers2

1

Navigation is limited to absolute and relative types. I think you mean to navigate to parent directory regardless of whole application location. Maybe you try relative path

string TAGPATH = "..\\tag_rw\\tagrw.exe"
1

Can you try this?

    static void Main(string[] args)
    {
        string cur = Environment.CurrentDirectory;
        Console.WriteLine(cur);
        string parent1 = Path.Combine(cur, @"..\");
        Console.WriteLine(new DirectoryInfo(parent1).FullName);
        string parent2 = Path.Combine(cur, @"..\..\");
        Console.WriteLine(new DirectoryInfo(parent2).FullName);
        Console.ReadLine();
    }
Lei Yang
  • 3,970
  • 6
  • 38
  • 59