Results 1 to 3 of 3

Thread: [RESOLVED] File Name From Open File Dialog

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    284

    Resolved [RESOLVED] File Name From Open File Dialog

    I am using this, to read 1+ files from the openFileDialog, but I am having a problem getting just the file name, I can get the location "C:\My Documents\filename.jpg" but how do I get just the name "filename.jpg"?

    I want to replace it with this line: can.Text = Regex.Replace(file, ".+\\$", "")
    vb.net Code:
    1. Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
    2.         Dim files
    3.         openFile.InitialDirectory = "C:\"
    4.         If openFile.ShowDialog = Windows.Forms.DialogResult.OK Then
    5.             files = openFile.FileNames
    6.             Dim f
    7.             Dim i = 0
    8.             For Each file In files
    9.                 Dim can As New Canvas
    10.                 f = Image.FromFile(file)
    11.                 can.contCanvas.Width = f.Width
    12.                 can.contCanvas.Height = f.Height
    13.                 can.MdiParent = Me
    14.                 can.Text = Regex.Replace(file, ".+\\$", "")
    15.                 Dim h = f.Height, w = f.Width
    16.                 can.ClientSize = New Size(w, h)
    17.                 can.Show()
    18.                 Dim layer = New Layer("layer0", can.contCanvas, can.mnu)
    19.                 layer.setImage(f)
    20.                 i += 1
    21.             Next
    22.         End If
    23.     End Sub
    I am still very new to VB.NET, so I have MANY questions

  2. #2
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: File Name From Open File Dialog

    To get only the name just use the IO namespace....

    VB.NET Code:
    1. IO.Path.GetFileName(file)

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    284

    Re: [RESOLVED] File Name From Open File Dialog

    Thanks!
    I am still very new to VB.NET, so I have MANY questions

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width