neo Posted November 15, 2006 Posted November 15, 2006 Hi everyone,I have trouble to get full path of a (*.txt) fileMy code with open dialog box===============================================================Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim myStream As StreamDim openFileDialog1 As New OpenFileDialog()openFileDialog1.InitialDirectory = "%Userprofile%"openFileDialog1.Filter = "Text files (*.txt)|*.txt"openFileDialog1.FilterIndex = 1openFileDialog1.RestoreDirectory = TrueIf openFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK ThenmyStream = 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 filesDim fullPath As StringfullPath = Path.GetFullPath(fileName)'checking! file is in correct formatMsgBox(fullPath)'close mystreammyStream.Close()End IfEnd IfEnd 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
jcarle Posted November 15, 2006 Posted November 15, 2006 (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 filesDim fullPath As StringfullPath = Path.GetFullPath(fileName)'checking! file is in correct formatMsgBox(fullPath)'close mystreammyStream.Close()End IfUse: If Not (myStream Is Nothing) ThenDim fileName As String = openFileDialog1.FilenamemyStream.Close()End If Edited November 15, 2006 by jcarle
neo Posted November 16, 2006 Author Posted November 16, 2006 Thanks it workssuperub coding5 Lines = 1 Line
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now