Click here to Skip to main content
16,012,508 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
here in the below coding the full path of the file is displayed ,, ehat is the procedure to display only the "file-name.extension"
<pre lang="vb">Public Class Form1

    Dim fdlg As OpenFileDialog = New OpenFileDialog()

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        fdlg.Title = "open"
        fdlg.InitialDirectory = "c:\"
        fdlg.Filter = "All files(*.*)|*.*|RTF files(*.rtf)|*.rtf|document files(*.doc)|*.doc"
        fdlg.FilterIndex = 1
        fdlg.RestoreDirectory = True
        If fdlg.ShowDialog = Windows.Forms.DialogResult.OK Then
            ListBox1.Items.Add(fdlg.FileName)
            MessageBox.Show("You selected " & fdlg.FileName)
        End If

    End Sub
Posted
Comments
Amol_27101982, India 11-Nov-11 2:20am    
If you got your solution that you are looking for then please mark it as your answer.
ANANTH P 11-Nov-11 2:39am    
oh thank u now i got it, but while selecting the rtf files, the rtf file alone displaying,after selecting the .doc file both the files are visible , how can i do to make visible either .doc or .rtf file type using vb.net coding

 
Share this answer
 
Use System.IO.Path.GetFileName to extract a file name from full path name, http://msdn.microsoft.com/en-us/library/system.io.path.getfilename.aspx[^].

Search MSDN and the Web by yourself to get more results faster.

—SA
 
Share this answer
 
use following code

string FilePath = fdlg.FileName;

MessageBox.Show("You selected " & Path.GetFileName(FilePath));

~Amol
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900