Jump to content

Recommended Posts

Posted

Hi everyone,

I have trouble to get full path of a (*.txt) file

My code with open dialog box

===============================================================

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim myStream As Stream

Dim openFileDialog1 As New OpenFileDialog()

openFileDialog1.InitialDirectory = "%Userprofile%"

openFileDialog1.Filter = "Text files (*.txt)|*.txt"

openFileDialog1.FilterIndex = 1

openFileDialog1.RestoreDirectory = True

If openFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then

myStream = openFileDialog1.OpenFile()

If Not (myStream Is Nothing) Then

' GetFullPath('myfile.txt')

Dim fileName As String = "myfile.txt" ////Also I don't want to get path of predefined files

Dim fullPath As String

fullPath = Path.GetFullPath(fileName)

'checking! file is in correct format

MsgBox(fullPath)

'close mystream

myStream.Close()

End If

End If

End Sub===================================================================

when i select a text file from desktop , it retrives path "C:\Users\Administrator\Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\bin\Debug\(Name of text file)"

its mean this path from app.exe dir


Posted (edited)

Instead of:

If Not (myStream Is Nothing) Then
' GetFullPath('myfile.txt')
Dim fileName As String = "myfile.txt" ////Also I don't want to get path of predefined files
Dim fullPath As String
fullPath = Path.GetFullPath(fileName)
'checking! file is in correct format
MsgBox(fullPath)
'close mystream
myStream.Close()
End If

Use:

If Not (myStream Is Nothing) Then
Dim fileName As String = openFileDialog1.Filename
myStream.Close()
End If

Edited by jcarle

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...