Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Application Path

Application Path

Scheduled Pinned Locked Moved Visual Basic
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SuperGeek
    wrote on last edited by
    #1

    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?

    W 1 Reply Last reply
    0
    • S SuperGeek

      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?

      W Offline
      W Offline
      Wayne Phipps
      wrote on last edited by
      #2

      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

      N 1 Reply Last reply
      0
      • W Wayne Phipps

        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

        N Offline
        N Offline
        Nick Seng
        wrote on last edited by
        #3

        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

        W 1 Reply Last reply
        0
        • N Nick Seng

          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

          W Offline
          W Offline
          Wayne Phipps
          wrote on last edited by
          #4

          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 Namespace

          W 1 Reply Last reply
          0
          • W Wayne Phipps

            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 Namespace

            W Offline
            W Offline
            Wayne Phipps
            wrote on last edited by
            #5

            I just tried it in VB.Net by the following: TextBox1 = Application.StartupPath Worked fine ;P

            N 1 Reply Last reply
            0
            • W Wayne Phipps

              I just tried it in VB.Net by the following: TextBox1 = Application.StartupPath Worked fine ;P

              N Offline
              N Offline
              Nick Seng
              wrote on last edited by
              #6

              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

              W 1 Reply Last reply
              0
              • N Nick Seng

                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

                W Offline
                W Offline
                Wayne Phipps
                wrote on last edited by
                #7

                I didn't add any Imports to the code, just added a TextBox to the form and added TextBox1.Text = Application.StartupPath to the Form1_Load. That should be all you need!

                N 1 Reply Last reply
                0
                • W Wayne Phipps

                  I didn't add any Imports to the code, just added a TextBox to the form and added TextBox1.Text = Application.StartupPath to the Form1_Load. That should be all you need!

                  N Offline
                  N Offline
                  Nick Seng
                  wrote on last edited by
                  #8

                  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

                  W 1 Reply Last reply
                  0
                  • N Nick Seng

                    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

                    W Offline
                    W Offline
                    Wayne Phipps
                    wrote on last edited by
                    #9

                    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.

                    N 1 Reply Last reply
                    0
                    • W Wayne Phipps

                      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.

                      N Offline
                      N Offline
                      Nick Seng
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups