• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1356
  • Last Modified:

VB6>GetPath in .NET

In VB6 you had the ability to use VB6.GetPath, what is the equivalent in VB.NET??
0
CodeDeamon
Asked:
CodeDeamon
  • 4
  • 3
  • 3
1 Solution
 
NetPointerCommented:
what does this getpath do?
0
 
CodeDeamonAuthor Commented:
Returns the path of where the application is located.
0
 
NetPointerCommented:
Application.StartupPath
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
CodeDeamonAuthor Commented:
Yeah, I have tried the Application namespace.  However, I always get an error saying it is not declared.
0
 
CodeDeamonAuthor Commented:
By the way, this is not on a form.
0
 
brother7Commented:
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
 
brother7Commented:
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
 
CodeDeamonAuthor Commented:
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
 
brother7Commented:
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
 
NetPointerCommented:
Try one of the following.

System.Windows.Forms.Application.ExecutablePath

System.Windows.Forms.Application.StartupPath

System.AppDomain.CurrentDomain.BaseDirectory()

System.GetEntryAssembly().Location

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now