简体   繁体   中英

.NET - How to get all video formats instead of specifying each format

How to get all document formats instead of specifying explicitly (ie -> .pdf, .doc etc) ?

Similarly, how do I get all video formats instead of specifying explicitly all video formats?

OpenFileDialog ofd = new OpenFileDialog();

ofd.filter = "DOCUMENT|*.pdf";  //filter document without giving all formats explicitly.

The filter mechanism works by file extension only. You can list multiple extensions per group and break the list into multiple groups like this:

.Filter = "Video Files (*.avi, *.mp4)|*.avi;*.mp4|Document Files (*.pdf, *.doc, *.docx, *.txt)|*.pdf;*.doc;*.docx;*.txt|All Files (*.*)|*.*"

But this will always require you to be explicit about the exact list of file extensions you want to support.

You can construct the Filter definition string programmatically, so if you're hoping to somehow locate all files with the same class (according to the shell) or mime type , then you'll have to create a filter from some authoritative source of your choosing. Possibly either by probing the system registry , or by using an up-to-date mime type map .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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