Sari
Sari

Reputation: 41

How to get winform fullpath?

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

Answers (6)

JediOfTheShire
JediOfTheShire

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

Narinder Bhullar
Narinder Bhullar

Reputation: 70

You can also use

Environment.CurrentDirectory It will get you the fully qualified path of working directory.

Upvotes: 0

briddums
briddums

Reputation: 1846

This information is part of the My namespace. The directory path can be found via My.Application.Info.DirectoryPath

Upvotes: 0

adrianbanks
adrianbanks

Reputation: 82994

As you are using WinForms, there are two simple properties to choose from on the Application class:

Upvotes: 2

poupou
poupou

Reputation: 43553

You can call Assembly.GetEntryAssembly ().CodeBase (or Location) from a Windows-Form application (but not from ASP.NET applications).

Upvotes: 0

Arun
Arun

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

Related Questions