仅从浏览选项中提取文件名 [英] extracting filename alone from browsing option

查看:91
本文介绍了仅从浏览选项中提取文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,显示文件的完整路径,这是仅显示"file-name.extension"的过程.

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

推荐答案

使用Path.GetFileName(path)

请参阅此处: http://msdn.microsoft.com /en-us/library/system.io.path_members%28v=vs.71%29.aspx [
Use Path.GetFileName(path)

See here : http://msdn.microsoft.com/en-us/library/system.io.path_members%28v=vs.71%29.aspx[^]


使用System.IO.Path.GetFileName提取完整路径名中的文件名, http://msdn.microsoft.com/en -us/library/system.io.path.getfilename.aspx [ ^ ].

自己搜索MSDN和Web,以更快地获得更多结果.

—SA
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


使用以下代码

字符串FilePath = fdlg.FileName;

MessageBox.Show(您选择了"& Path.GetFileName(FilePath));

〜Amol
use following code

string FilePath = fdlg.FileName;

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

~Amol


这篇关于仅从浏览选项中提取文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆