We help IT Professionals succeed at work.

VB.NET how to get "own" file location

431 Views
Last Modified: 2012-05-08
Hi X-perts,

It is a simple question - how can I get a file "own" location in VB.NET and its root directory?

I need to reference files that in a root directory relative to my file.

Please, advise

Thanks
Comment
Watch Question

Commented:
Hi,

If the file is in you application directory:

IO.Path.GetFullPath(Application.StartupPath & "\filename.txt")

Let me know if this is not your solution.

Author

Commented:
thank you, but it is not my solution. In my case, the  Application.StartupPath points to MS Excel Program Files, because the application is excel. But the file I need to find location is a DLL assembly. I have managed to get its location via reflection, but still looking for something better

Commented:
Hi,

Would you be more specific? Do you want to search for a file? And return its location? What if there are more than one result?
CERTIFIED EXPERT

Commented:
Use Application.ExecutablePath().

Wayne

Author

Commented:
No, it doesn't work:

1) I start Excel application, which references a DLL file which is in a different location.

2) I need to add a code into that DLL file to get its location.

I tried all these solutions, i.e. Application.ExecutablePath(), Application.StartupPath  etc

The only way I have found so far is this one:

Dim aPath As String = System.Reflection.Assembly.GetExecutingAssembly.Location

It returns a full path to that DLL file, but I need to manipulate with its string to get directories
ROMA CHAUHANProject Lead
CERTIFIED EXPERT

Commented:
ROMA CHAUHANProject Lead
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.