我试图只包括我在label1.Text属性中的OpenFileDialog中选择的文件的文件名,但我还没有找到解决方案.我知道我可以使用ofd实例上的字符串类中的方法来过滤掉文件的整个路径,但我想知道是否存在更智能/更快捷的方法?
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Find song";
ofd.Filter = "MP3 files|*.mp3";
ofd.InitialDirectory = @"C:\";
if (ofd.ShowDialog() == DialogResult.OK)
{
label1.Text = "" + ofd.FileName +"";
}
Run Code Online (Sandbox Code Playgroud) 我想保存文件应该保存的路径,但我不希望用户添加文件的名称及其格式.只需选择应保存文件的地图.
下面的代码不能保存路径,因为您还需要添加文件名.
SaveFileDialog saveFileDialog = new SaveFileDialog();
if (saveFileDialog.ShowDialog() == true)
{
lblDestination.Content = saveFileDialog.FileName;
}
Run Code Online (Sandbox Code Playgroud)
谢谢!