Application Path
-
Here is what I hope will be a simple question. In the old VB6, we could use the app.path to get the application path. What do I used to do this in VB.NET?
Is this is what your looking for... The following example gets this property and displays its value in a text box. The example assumes that textBox1 has been placed on a form.
Private Sub PrintStartupPath() textBox1.Text = "The path for the executable file that " & _ "started the application is: " & _ Application.StartupPath End Sub
-
Is this is what your looking for... The following example gets this property and displays its value in a text box. The example assumes that textBox1 has been placed on a form.
Private Sub PrintStartupPath() textBox1.Text = "The path for the executable file that " & _ "started the application is: " & _ Application.StartupPath End Sub
Application.StartupPath only works in Vb6 In vb.net, you have 2 choices that work: 1) System.Reflection.Assembly.GetExecutingAssembly.Location 2) System.IO.Directory.GetCurrentFolder I hope this helps Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
Get your facts first, and then you can distort them as much as you please Mark Twain -
Application.StartupPath only works in Vb6 In vb.net, you have 2 choices that work: 1) System.Reflection.Assembly.GetExecutingAssembly.Location 2) System.IO.Directory.GetCurrentFolder I hope this helps Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
Get your facts first, and then you can distort them as much as you please Mark TwainIf Application.StartupPath is only applicable to VB6 then why did that sample come from the .Net Framework class library? I ask this question because I have just upgraded from Visual Studio 6 to Visual Studion .Net Pro and this sample came from the .Net help. Visual Studio 6 is now not installed. Here is the complette sample... .NET Framework Class Library Application.StartupPath Property [Visual Basic] Public Shared ReadOnly Property StartupPath As String Property Value The path for the executable file that started the application. Example [Visual Basic, C#] The following example gets this property and displays its value in a text box. The example assumes that textBox1 has been placed on a form.
Private Sub PrintStartupPath() textBox1.Text = "The path for the executable file that " & _ "started the application is: " & _ Application.StartupPath End Sub
Requirements Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server family .NET Framework Security: FileIOPermission for reading and writing files. Associated enumeration: FileIOPermissionAccess.Read See Also Application Class | Application Members | System.Windows.Forms Namespace -
If Application.StartupPath is only applicable to VB6 then why did that sample come from the .Net Framework class library? I ask this question because I have just upgraded from Visual Studio 6 to Visual Studion .Net Pro and this sample came from the .Net help. Visual Studio 6 is now not installed. Here is the complette sample... .NET Framework Class Library Application.StartupPath Property [Visual Basic] Public Shared ReadOnly Property StartupPath As String Property Value The path for the executable file that started the application. Example [Visual Basic, C#] The following example gets this property and displays its value in a text box. The example assumes that textBox1 has been placed on a form.
Private Sub PrintStartupPath() textBox1.Text = "The path for the executable file that " & _ "started the application is: " & _ Application.StartupPath End Sub
Requirements Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server family .NET Framework Security: FileIOPermission for reading and writing files. Associated enumeration: FileIOPermissionAccess.Read See Also Application Class | Application Members | System.Windows.Forms NamespaceI just tried it in VB.Net by the following: TextBox1 = Application.StartupPath Worked fine ;P
-
I just tried it in VB.Net by the following: TextBox1 = Application.StartupPath Worked fine ;P
BusterG wrote: TextBox1 = Application.StartupPath This is really weird coz
Application.StartupPath
doesn't work for me! Is there some other namespace or something that i'm suppose to add???:~ Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
Get your facts first, and then you can distort them as much as you please Mark Twain -
BusterG wrote: TextBox1 = Application.StartupPath This is really weird coz
Application.StartupPath
doesn't work for me! Is there some other namespace or something that i'm suppose to add???:~ Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
Get your facts first, and then you can distort them as much as you please Mark TwainI didn't add any
Imports
to the code, just added a TextBox to the form and addedTextBox1.Text = Application.StartupPath
to theForm1_Load
. That should be all you need! -
I didn't add any
Imports
to the code, just added a TextBox to the form and addedTextBox1.Text = Application.StartupPath
to theForm1_Load
. That should be all you need!That's weird coz this doesn't work for me! The IDE doesn't even recognizes the
Application
keyword (i.e. there are squigly blue lines underneath the word saying it that 'Application' is not declared) Does anyone know why this happens? Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
Get your facts first, and then you can distort them as much as you please Mark Twain -
That's weird coz this doesn't work for me! The IDE doesn't even recognizes the
Application
keyword (i.e. there are squigly blue lines underneath the word saying it that 'Application' is not declared) Does anyone know why this happens? Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
Get your facts first, and then you can distort them as much as you please Mark TwainThe VB.Net help file states: Requirements Namespace: System.Windows.Forms I guess thats why it works without any other namespace declarations if you place the code in a form. So needless to say, if you declare
Imports System.Windows.Forms
it should work fine. -
The VB.Net help file states: Requirements Namespace: System.Windows.Forms I guess thats why it works without any other namespace declarations if you place the code in a form. So needless to say, if you declare
Imports System.Windows.Forms
it should work fine.OMG!!! :-O This is really embarassing.It works now. It didn't work before coz i was testing the code in a class library project ( which doesn't include system.windows.forms). I can't believe I was so blind/stupid!!:) Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
Get your facts first, and then you can distort them as much as you please Mark Twain