0

How to get the current project folder path?

    string str = Application.ExecutablePath;
    string scriptpath = Directory.GetParent(str).Parent.FullName;

C:\Users\<My User Name>\AppData\Local\Apps\2.0\MyFolder\MyFolder2\MyFolder3\file.exe

returns -> Folder Path with .exe file on it.

This syntax : Directory.GetParent(str).Parent.FullName returns the folder path .. C:\Users\\AppData\Local\Apps\2.0\MyFolder\MyFolder2\

I am not able to get the " C:\Users\<My User Name>\AppData\Local\Apps\2.0\MyFolder\MyFolder2\MyFolder3\ "

I need to get the folder path above the .exe file.

goofyui
  • 3,362
  • 20
  • 72
  • 128
  • You're asking for the *application's* directory, not the current directory. – Panagiotis Kanavos Jul 08 '19 at 14:24
  • Directory.GetParent(workingDirectory).Parent.FullName: You are going up two directory, is that where your scripts are? Also, are file's kept at that location? And I assume file exists there? – r2018 Jul 08 '19 at 14:31
  • Directory.GetParent(workingDirectory).Parent.FullName syntax returns the directory excluding bin / debug folder path such as c:\MyProject\ and then i am concatenating the SQL Script folder path and so it become as c:\MyProject\SQLScripts\DBScript.sql - This works fine from Development env / Debug mode. – goofyui Jul 08 '19 at 14:51

0 Answers0