Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Im going from VB6.0 to .NET and have a couple of questions.

 

My first one (and the only one Ill ask right now) is how do I handle flat text file IO. I have seen the examples below of this and those definatly help, but I don't want to hard code the path of the file.

 

In VB 6 I could use app.path with the rest of the file information to grab it, is there a .NET variance of app.path?

 

BTW I don't have the MSDN help libraries installed yet (waiting on the help desk guys to do that).

 

Thanks.

Posted

I use this class

 

This is the class I use to get the application path and also the exe name:

 

 

'Call it like so
Dim AppPath as New AppPath()

'Here is the class
Public Class AppPath
   Private mAppPath As String
   Private mExeName As String

   Public ReadOnly Property DirPath() As String
       Get
           Return mAppPath
       End Get
   End Property

   Public ReadOnly Property ExeName() As String
       Get
           Return mExeName
       End Get
   End Property

   Public Sub New()
       Dim p As Path
       Try
           mAppPath = System.Reflection.Assembly.GetExecutingAssembly.Location
           mExeName = Dir(mAppPath)
           mAppPath = p.GetFullPath((Left(mAppPath, (Len(mAppPath) - Len(mExeName)))))
       Catch
           MsgBox(Err.Description, MsgBoxStyle.Critical, "Error!")
       End Try
   End Sub
End Class

Note: the path that is returned is to the "bin" directory in your project directory.

When in doubt.... use the sledge Hammer!!
  • Leaders
Posted

as mutant was saying Application.ExecutablePath , that returns the path and exe name all in 1 line :

MessageBox.Show(Application.ExecutablePath)

 

to get just the start up directory ( minus the exe name ) this works :

MessageBox.Show(Application.StartupPath)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...