Reputation: 41
I have a winform and its fullpath is C:\test.exe
How do I get the winform fullpath at run time? For example, the user may move the winform to other places. Thanks.
Upvotes: 4
Views: 272
Reputation: 125
You should be prompted to add a reference to System.Reflection, but this should give you exactly what you want:
Assembly.GetExecutingAssembly().Location;
Upvotes: 0
Reputation: 70
You can also use
Environment.CurrentDirectory
It will get you the fully qualified path of working directory.
Upvotes: 0
Reputation: 1846
This information is part of the My namespace. The directory path can be found via My.Application.Info.DirectoryPath
Upvotes: 0
Reputation: 82994
As you are using WinForms, there are two simple properties to choose from on the Application
class:
Application.StartupPath
will get you the directory in which the application started.Application.ExecutablePath
will get you the full path to the application (including the filename).Upvotes: 2
Reputation: 43553
You can call Assembly.GetEntryAssembly ().CodeBase (or Location) from a Windows-Form application (but not from ASP.NET applications).
Upvotes: 0
Reputation: 2523
This would give you the file name: System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name
For folder name, try: System.Reflection.Assembly.GetExecutingAssembly().Location (not sure... on top of my head)
Upvotes: 0