MSFN Forum: Visal Basic 2005 (get Full Path) - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Visal Basic 2005 (get Full Path) How get full path of Text file Rate Topic: -----

#1 User is offline   neo 

  • Microsoft MVP - Windows Expert Consumer
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,251
  • Joined: 31-March 06
  • OS:Windows 7 x86
  • Country: Country Flag

Posted 15 November 2006 - 12:04 PM

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


#2 User is offline   jcarle 

  • MSFN Master
  • Group: Developers
  • Posts: 2,569
  • Joined: 14-August 04

Posted 15 November 2006 - 12:45 PM

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

This post has been edited by jcarle: 15 November 2006 - 12:45 PM


#3 User is offline   neo 

  • Microsoft MVP - Windows Expert Consumer
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,251
  • Joined: 31-March 06
  • OS:Windows 7 x86
  • Country: Country Flag

Posted 16 November 2006 - 12:09 AM

Thanks it works

superub coding
5 Lines = 1 Line

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy