Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB6>GetPath in .NET

Posted on 2003-11-05
10
Medium Priority
?
1,310 Views
Last Modified: 2007-12-19
In VB6 you had the ability to use VB6.GetPath, what is the equivalent in VB.NET??
0
Comment
Question by:CodeDeamon
  • 4
  • 3
  • 3
10 Comments
 
LVL 4

Expert Comment

by:NetPointer
ID: 9689639
what does this getpath do?
0
 

Author Comment

by:CodeDeamon
ID: 9689660
Returns the path of where the application is located.
0
 
LVL 4

Expert Comment

by:NetPointer
ID: 9689667
Application.StartupPath
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

Author Comment

by:CodeDeamon
ID: 9689698
Yeah, I have tried the Application namespace.  However, I always get an error saying it is not declared.
0
 

Author Comment

by:CodeDeamon
ID: 9689710
By the way, this is not on a form.
0
 
LVL 4

Expert Comment

by:brother7
ID: 9689914
You don't need to be using a windows form, but you do need to add a reference System.Windows.Forms.dll in order to use the Application.StartupPath property.

Try the following sample code:

--- Code Start ---

Imports System.Windows.Forms
Private Sub PrintStartupPath()
   textBox1.Text = "The path for the executable file that " & _
      "started the application is: " & _
      Application.StartupPath
End Sub

--- Code End ---
0
 
LVL 4

Expert Comment

by:brother7
ID: 9689937
Oops... forgot it wasn't a windows form.  Here's sample code using the Console: (don't forget to add the reference to the .dll with Project > Add Reference

--- Code Start ---
Imports System.Windows.Forms

Module Module1
   Sub Main()
      Console.Writeline("The path for the executable file that started the application is: " & Application.StartupPath)
   End Sub
End Module
--- Code End ---
0
 

Author Comment

by:CodeDeamon
ID: 9689976
I have tried to add the reference, I have already seen the code you are giving, but no matter what it says application is not declared.  It is a Class Library project if that matters.
0
 
LVL 4

Expert Comment

by:brother7
ID: 9690153
I just tried it and it works.

Here are the steps I performed.

1- Create new class library ClassLibrary1.
2- Add reference to Windows.System.Forms.dll
3- Enter the following code

--- Code Start ---
Imports System.Windows.Forms

Public Class Path
   Sub New()
      Console.WriteLine("The path for the executable file that started the application is: " & Application.StartupPath)
   End Sub
End Class
--- Code End ---

4- Build solution.
5- Close solution.
6- Create a new Console Application ConsoleApplication1.
7- Add reference to the Class library I just built, which is ClassLibrary1.dll  Note, you have to choose the Projects tab and surf to ClassLibrary1/bin to find the dll
8- Enter the following code

--- Code Start ---
Imports ClassLibrary1

Module Module1

   Sub Main()
      Dim path As Path = New Path()
   End Sub

End Module
--- Code End ---

9- Build and run.
0
 
LVL 4

Accepted Solution

by:
NetPointer earned 105 total points
ID: 9690206
Try one of the following.

System.Windows.Forms.Application.ExecutablePath

System.Windows.Forms.Application.StartupPath

System.AppDomain.CurrentDomain.BaseDirectory()

System.GetEntryAssembly().Location

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question