#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2001
    Location
    USA
    Posts
    313
    Rep Power
    19

    OpenFileDialog in VS.NET (VB)


    Ok in VB6 you could find the file name by using this.

    PHP Code:
    stFileName dlgBox.FileTitle 
    But in VB.NET on the OpenFileDialog I do not see the .FileTitle anymore. Do you have to manipulate the string or am I missing something?

    The .Title gives you the dialog box title not the title of the file itself. old VB6 was .FileTitle but .NET does not seem to have an equivilant value for this. I guess you could manipulate the string returned by .File cuase it returns the path and file name but it would be great if you could just get the filename.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2001
    Location
    USA
    Posts
    313
    Rep Power
    19
    Well I found the solution on www.gotdotnet.com. Thought if I posted it here other may be able to use it as well.

    PHP Code:
    Dim stFileName As String

    Dim openFileDialog1 
    As New OpenFileDialog

    openFileDialog1
    .InitialDirectory System.Environment.CurrentDirectory
    openFileDialog1
    .Title "Open Text File"
    openFileDialog1.Filter "Text files (*.txt)|*.txt"
    openFileDialog1.FilterIndex 1
    openFileDialog1
    .RestoreDirectory True

    If openFileDialog1.ShowDialog() = DialogResult.OK Then
        Dim stFilePathAndName 
    As String openFileDialog1.FileName
        Dim MyFile 
    As FileInfo = New FileInfo(stFilePathAndName)
        
    stFileName MyFile.Name
    End 
    If

    MessageBox.Show("Your File Info: " vbCrLf vbCrLf _
        
    "File Path and Name: " stFilePathAndName vbCrLf vbCrLf _
        
    "File Name: " stFileName_
        
    "File Info"_
        MessageBoxButtons
    .OK_
        MessageBoxIcon
    .Information
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    1
    Rep Power
    0
    Originally Posted by iamtgo3
    Well I found the solution on 'Guess I am not aloud to reply with url entered ' Thought if I posted it here other may be able to use it as well.

    PHP Code:
    Dim stFileName As String

    Dim openFileDialog1 
    As New OpenFileDialog

    openFileDialog1
    .InitialDirectory System.Environment.CurrentDirectory
    openFileDialog1
    .Title "Open Text File"
    openFileDialog1.Filter "Text files (*.txt)|*.txt"
    openFileDialog1.FilterIndex 1
    openFileDialog1
    .RestoreDirectory True

    If openFileDialog1.ShowDialog() = DialogResult.OK Then
        Dim stFilePathAndName 
    As String openFileDialog1.FileName
        Dim MyFile 
    As FileInfo = New FileInfo(stFilePathAndName)
        
    stFileName MyFile.Name
    End 
    If

    MessageBox.Show("Your File Info: " vbCrLf vbCrLf _
        
    "File Path and Name: " stFilePathAndName vbCrLf vbCrLf _
        
    "File Name: " stFileName_
        
    "File Info"_
        MessageBoxButtons
    .OK_
        MessageBoxIcon
    .Information
    Some minor notes:
    1) You need to import "System.IO"
    2) You should not create a variable in an "if" statement[/list]

IMN logo majestic logo threadwatch logo seochat tools logo