-
Jan 17th, 2018, 12:53 PM
#1
Thread Starter
Addicted Member
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.
-
Jan 17th, 2018, 01:16 PM
#2
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
-
Jan 17th, 2018, 06:38 PM
#3
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:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|