In the. NET Framework, Microsoft has encapsulated a dialog box--openfiledialog for opening a file. The dialog box contains a property--filter that can filter the file, which, with this property, can optionally filter out the files we need.
?? Therefore, it is necessary to remember the format of the Filter property. The format is divided into two situations:
1 // A filter item contains multiple formats 2 " image file (*.gif;*.png;*.jpg;*.bmp;*.ico) |*.gif;*.png;*.jpg;*.bmp;*.ico " ; 3 // Multiple filter Items 4 ofd. Filter = "PDF file (*.pdf) |*.pdf| text file (*.txt) |*.txt";
Example : If the Filter property is set as follows:
1Ofd. Filter ="All Files (*. *) |*.*"+"|"+2 "text file (*.txt) |*.txt"+"|"+3 "PDF file (*.pdf) |*.pdf"+"|"+4 "Office Documents (*.DOC;*.DOCX;*.XLS;*.XLSX;*.PPT;*.PPTX) |*.doc;*.docx;*.xls;*.xlsx;*.ppt;*.pptx"+"|"+5 "image file (*.gif;*.png;*.jpg;*.jpeg;*.bmp;*.ico) |*.gif;*.png;*.jpg;*.jpeg;*.bmp;*.ico"+"|"+6 "audio files (*.mp3;*.mid;*.wav;) |*.mp3;*.mid;*.wav;"+"|"+7 "video file (*.mp4;*.avi;*.rmvb;*.wmv;*.mkv;*.flv) |*.mp4;*.avi;*.rmvb;*.wmv;*.mkv;*.flv"+"|"+8 "compressed Files (*.rar;*.zip;*.7z) |*.rar;*.zip;*.7z"+"|"+9 "HTML file (*.htm;*.html) |*.htm;*.html"+"|"+Ten "XML file (*.xml;*.xaml) |*.xml;*.xaml"+"|"+ One "code file (*.c;*.cpp;*.h;*.hpp;*.cs;*.java) |*.c;*.cpp;*.h;*.hpp;*.cs;*.java"+"|"+ A "Program Files (*.exe;*.dll;*.jar;*.class) |*.exe;*.dll;*.jar;*.class";
Article Sync update: http://www.motyer.cn/Files/BlogDetails/winform-file-filter.html
WinForm file Filter