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#? 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开发者_C百科 for display in a picturebox. Having trouble finding a solution for this. Cheers.
Use OpenFileDialog.FileName
:
if(openFileDialog.ShowDialog() == DialogResult.OK)
{
InsertIntoList(openFileDialog.FileName);
}
Have you tried using openfiledialog.FileName
property?
use openFileDialog.SafeFileName
to get just the name of the file
openFileDialog.FileName
returns the full path to the file
精彩评论