0

I have a folder in c:\program files(x86)\company\application\ which contains all the app files.

How can I get the path like C:\program files(x86)\company?

I cannot use Application.Startuppath as it will return c:\program files)x86)\company\application.

Thanks.

Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208
kyusan93
  • 312
  • 1
  • 7
  • 19
  • 1
    Does "c:\program files)x86)\company\application\..\" work for you? –  May 17 '12 at 06:20
  • duplicate http://stackoverflow.com/questions/401304/c-sharp-how-do-i-extract-each-folder-name-from-a-path – FosterZ May 17 '12 at 06:24

3 Answers3

3

Use Directory.GetParent(string path)

In your app include System.IO namespace

using System.IO;

and use

string desired_path = Directory.GetParent(Application.StartupPath);
                       // will return c:\program files(x86)\company
        // because app path will have c:\program files(x86)\company\application\
Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208
0

See This MSDN Content about System.IO.Path.GetDirectoryName(string)

So, Include :

using System.IO;

Now Your Code:

string ApplicationPath = Application.StartupPath;
string YourPath = Path.GetDirectoryName(ApplicationPath);
// This will get "C:\program files(x86)\company" from "C:\program files(x86)\company\application"
Writwick
  • 2,133
  • 6
  • 23
  • 54
0

Best to use Environment.CurrentDirectory and it will help you.

Please refer http://msdn.microsoft.com/en-us/library/system.environment.currentdirectory%28v=vs.71%29.aspx

for more details.

Shailesh
  • 1,178
  • 11
  • 12