简体   繁体   English

C#获取在openfile对话框中打开的文件的文件名

[英]C# getting the filename of a file you open in the openfiledialog

Is there a way to get the file name of a file you open using the openfiledialog in C#? 有没有办法使用C#中的openfile对话框来获取您打开的文件的文件名? I need this because, the user is going to open an image file, but then the image file is added to a listbox(using its filename), then can be selected for display in a picturebox. 我需要这样做,因为用户将要打开一个图像文件,但是随后将图像文件添加到列表框(使用其文件名),然后可以选择将其显示在图片框中。 Having trouble finding a solution for this. 找不到解决方案。 Cheers. 干杯。

Use OpenFileDialog.FileName : 使用OpenFileDialog.FileName

if(openFileDialog.ShowDialog() == DialogResult.OK)
{
    InsertIntoList(openFileDialog.FileName);
}

use openFileDialog.SafeFileName to get just the name of the file 使用openFileDialog.SafeFileName仅获取文件名

openFileDialog.FileName returns the full path to the file openFileDialog.FileName返回文件的完整路径

您是否尝试过使用openfiledialog.FileName属性?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM