OpenFileDialog Help

Hey guys I've found a couple of posts about this but I just can't seem to pull it off in my program. What I want to do is use 'OpenFileDalog' to take the filename from a file the user selects, so I can assign it to a variable. I dont want the the path or file extention.

Heres the program i want to change:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim openFile As String
OpenFileDialog1.ShowDialog()
openFile = OpenFileDialog1.FileName
Text1.Text = openFile
End Sub

Cheers.

Comments

  • : Hey guys I've found a couple of posts about this but I just can't
    : seem to pull it off in my program. What I want to do is use
    : 'OpenFileDalog' to take the filename from a file the user selects,
    : so I can assign it to a variable. I dont want the the path or file
    : extention.
    :
    : Heres the program i want to change:
    :
    : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    : System.EventArgs) Handles Button1.Click
    : Dim openFile As String
    : OpenFileDialog1.ShowDialog()
    : openFile = OpenFileDialog1.FileName
    : Text1.Text = openFile
    : End Sub
    :
    : Cheers.
    :

    To just select the filename without extension use:
    [code]
    Dim sFile As String = OpenFileDialog1.FileName
    Dim sName As String

    sName = Strings.Right(sFile, Len(sFile) - Strings.InStrRev(sFile, ""))
    sName = Strings.Left(sName, Strings.InStrRev(sName, "."))

    MsgBox("File 'name' is " & sName)
    [/code]

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • : : Hey guys I've found a couple of posts about this but I just can't
    : : seem to pull it off in my program. What I want to do is use
    : : 'OpenFileDalog' to take the filename from a file the user selects,
    : : so I can assign it to a variable. I dont want the the path or file
    : : extention.
    : :
    : : Heres the program i want to change:
    : :
    : : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    : : System.EventArgs) Handles Button1.Click
    : : Dim openFile As String
    : : OpenFileDialog1.ShowDialog()
    : : openFile = OpenFileDialog1.FileName
    : : Text1.Text = openFile
    : : End Sub
    : :
    : : Cheers.
    : :
    :
    : To just select the filename without extension use:
    : [code]:
    : Dim sFile As String = OpenFileDialog1.FileName
    : Dim sName As String
    :
    : sName = Strings.Right(sFile, Len(sFile) - Strings.InStrRev(sFile, ""))
    : sName = Strings.Left(sName, Strings.InStrRev(sName, "."))
    :
    : MsgBox("File 'name' is " & sName)
    : [/code]:
    :
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry
    Thats great, thanks.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories