Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get file extension from OpenFileDialog?

I want just get Image(.JPG,.PNG,.Gif) File from my OpenFileDialog How can I get file extension from OpenFileDialog?

Is it impossible?

like image 805
M.Azad Avatar asked Mar 26 '12 12:03

M.Azad


People also ask

What is the file extension of VB net?

There is a VBScript, the extension for that files would be VBS.

Which property of OpenFileDialog is set to add extension?

AddExtension Property (System.

Which property of OpenFileDialog is set to add extension to file names if the user does not supply an extension?

From FileDialog. AddExtension Property: "Gets or sets a value indicating whether the dialog box automatically adds an extension to a file name if the user omits the extension."


1 Answers

To filter only certain types of file use Filter Property

OpenFileDialog1.Filter = "Image Files (JPG,PNG,GIF)|*.JPG;*.PNG;*.GIF"; 

To get the file extension use the Path helper GetFileExtension

if (OpenFileDialog1.ShowDialog() == DialogResult.OK)    string ext = Path.GetExtension(OpenFileDialog1.FileName); 
like image 68
Steve Avatar answered Sep 21 '22 12:09

Steve