getting a file name

I am able to get a file into a richtextbox, by useing openfiledialog. i wanted to name the title of the form, the name of the file. I thought it would be as simple as openfiledialog1.filename. It would be, except for the fact that it gives the location as well as the name. any ideas?

Comments

  • Hi, here's one possibility

    Dim sFile as string
    Dim nPos as integer

    OpenDialog.ShowDialog
    sFile = OpenDialog.FileName 'e.g. File = "C:DocumentsMyDoc.doc"
    nPos = InstrRev(sFile, "") 'Retrieve position of last slash

    'If you want the file extension as well
    sFile = sFile.Substring(nPos) 'sFile = "MyDoc.doc"
    'Else you don't want the file extension
    sFile = sFile.Substring(nPos, Len(sFile) - nPos - 4) 'sFile = "MyDoc"

    Obviously you may have to do some checks to make sure that the slash exists and that nPos <> 0 (in case the user hit Cancel).

    Hope this helps,
    Chris


    : I am able to get a file into a richtextbox, by useing openfiledialog. i wanted to name the title of the form, the name of the file. I thought it would be as simple as openfiledialog1.filename. It would be, except for the fact that it gives the location as well as the name. any ideas?
    :

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

In this Discussion