Results 1 to 3 of 3

Thread: Debbuger Mode - Application Path

  1. #1

    Thread Starter
    Addicted Member sinner0636's Avatar
    Join Date
    Sep 2009
    Posts
    233

    Debbuger Mode - Application Path

    Hello
    i was wondering how i can get the debber application path that way i can still do things that i would when not running in debug mode i kinda have it but not 100% can this be done? thanks

    Module
    Code:
              Public ApplicationName As String = Application.ProductName
              Public ApplicationPath As String = Application.ExecutablePath
    
            Public Function AbsoluteFolderPath(ByVal FilePath As String) As String
            Try
                Dim f As FileInfo
                f = My.Computer.FileSystem.GetFileInfo(FilePath)
                Dim folderPath As String = f.DirectoryName
                Return folderPath
            Catch ex As Exception
                'err
            End Try
        End Function
    
        Public Function AbsoluteFilePath(ByVal FPath As String) As String
            Try
                Dim f As FileInfo
                f = My.Computer.FileSystem.GetFileInfo(FPath)
                Dim fileName As String = f.Name
                Return fileName
            Catch ex As Exception
                'err
            End Try
        End Function
    Form Load
    Code:
            'Check if debugging for developers use
            If Debugger.IsAttached Then
                CurrentWorkingDirectory = AbsoluteFolderPath(ApplicationPath)
                MsgBox(CurrentWorkingDirectory)
            Else
                CurrentWorkingDirectory = AbsoluteFolderPath(ApplicationPath)
                MsgBox(CurrentWorkingDirectory)
            End If
    Last edited by sinner0636; Jan 17th, 2018 at 01:02 PM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Debbuger Mode - Application Path

    Yeah, you might be able to get it, but it begs the question of why you would want it? If you want to access files, they probably shouldn't be in the path with the application, whether debugging or not. I suppose it could be useful to have a static item in the same folder, though it seems like that ought to be a resource, but if it is for anything else, it would be better to use one of the Windows Special Folders:

    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
    My usual boring signature: Nothing

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Debbuger Mode - Application Path

    I'm not sure I understand the issue. Application.ExecutablePath gives you the full path of the EXE used to run the application. That is true whether you're debugging or not. Application.StartupPath is similar but is the path of the folder containing the EXE. For instance, if you have a text file in the subfolder of your program folder then you can open it like this:
    vb.net Code:
    1. Using reader As New StreamReader(Path.Combine(Application.StartupPath, "Subfolder\File.txt")
    That will work while debugging in your IDE and on an end-user's machine after deployment. Is that what you want?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width