Reputation: 422
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.
Upvotes: 0
Views: 2418
Reputation: 2163
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"
Upvotes: 0
Reputation: 48580
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\
Upvotes: 3
Reputation: 1218
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.
Upvotes: 0