Don't show filter extensions in OpenFileDialog

Why not filter extenstions in OpenFileDialog

? I tested this, but the dialog doesn't show the DAT

extenstion extension . If I get ext1 to ext1 then OpenFileDialog

filters in the dialog. I am using C#

Application-FrameWork 3.5 - on Win XP.

Here is my code:

OpenFileDialog openFileDialog = new OpenFileDialog();

string VideoFormat = "Video files |*.wmv; *.3g2; *.3gp; *.3gp2; *.3gpp; *.amv; *.asf;  *.avi; *.bin; *.cue; *.divx; *.dv; *.flv; *.gxf; *.iso; *.m1v; *.m2v; *.m2t; *.m2ts; *.m4v; " +
                          " *.mkv; *.mov; *.mp2; *.mp2v; *.mp4; *.mp4v; *.mpa; *.mpe; *.mpeg; *.mpeg1; *.mpeg2; *.mpeg4; *.mpg; *.mpv2; *.mts; *.nsv; *.nuv; *.ogg; *.ogm; *.ogv; *.ogx; *.ps; *.rec; *.rm; *.rmvb; *.tod; *.ts; *.tts; *.vob; *.vro; *.webm; *.dat; ";


openFileDialog.Filter = VideoFormat;
openFileDialog.ShowDialog();

      

but this code filtered out the DAT extension in the dialog:

OpenFileDialog openFileDialog = new OpenFileDialog();

            string VideoFormat = "Video files | *.dat; *.wmv; *.3g2; *.3gp; *.3gp2; *.3gpp; *.amv; *.asf;  *.avi; *.bin; *.cue; *.divx; *.dv; *.flv; *.gxf; *.iso; *.m1v; *.m2v; *.m2t; *.m2ts; *.m4v; " +
                      " *.mkv; *.mov; *.mp2; *.mp2v; *.mp4; *.mp4v; *.mpa; *.mpe; *.mpeg; *.mpeg1; *.mpeg2; *.mpeg4; *.mpg; *.mpv2; *.mts; *.nsv; *.nuv; *.ogg; *.ogm; *.ogv; *.ogx; *.ps; *.rec; *.rm; *.rmvb; *.tod; *.ts; *.tts; *.vob; *.vro; *.webm; ";


openFileDialog.Filter = VideoFormat;
openFileDialog.ShowDialog();

      

+3


source to share


1 answer


This is the correct formatting of the Filter property of your object OpenFileDialog

:

(*.jpg)|*.jpg|Image Files (*.png)|*.png|Image Files (*.jpeg)|*.jpeg

      

Try the following:

        OpenFileDialog openFileDialog = new OpenFileDialog();
        string formats = "*.dat; *.wmv; *.3g2; *.3gp; *.3gp2; *.3gpp; *.amv; *.asf;  *.avi; *.bin; *.cue; *.divx; *.dv; *.flv; *.gxf; *.iso; *.m1v; *.m2v; *.m2t; *.m2ts; *.m4v; " +
                  " *.mkv; *.mov; *.mp2; *.mp2v; *.mp4; *.mp4v; *.mpa; *.mpe; *.mpeg; *.mpeg1; *.mpeg2; *.mpeg4; *.mpg; *.mpv2; *.mts; *.nsv; *.nuv; *.ogg; *.ogm; *.ogv; *.ogx; *.ps; *.rec; *.rm; *.rmvb; *.tod; *.ts; *.tts; *.vob; *.vro; *.webm";

        string[] exts = formats.Split(';');
        string filter = string.Empty;
        foreach (string ext in exts)
        {

                filter += "Video Files (" + ext.Replace("*", "").Trim() + ")|" + ext + "|";
        }

        openFileDialog.Filter = filter.Remove(filter.Length-1,1);
        openFileDialog.ShowDialog();

      



UPDATE

This only shows one option, but you can select all video types:

        OpenFileDialog openFileDialog = new OpenFileDialog();
        string formats = "All Videos Files |*.dat; *.wmv; *.3g2; *.3gp; *.3gp2; *.3gpp; *.amv; *.asf;  *.avi; *.bin; *.cue; *.divx; *.dv; *.flv; *.gxf; *.iso; *.m1v; *.m2v; *.m2t; *.m2ts; *.m4v; " +
                  " *.mkv; *.mov; *.mp2; *.mp2v; *.mp4; *.mp4v; *.mpa; *.mpe; *.mpeg; *.mpeg1; *.mpeg2; *.mpeg4; *.mpg; *.mpv2; *.mts; *.nsv; *.nuv; *.ogg; *.ogm; *.ogv; *.ogx; *.ps; *.rec; *.rm; *.rmvb; *.tod; *.ts; *.tts; *.vob; *.vro; *.webm";

        openFileDialog.Filter = formats;
        openFileDialog.ShowDialog();

      

It should be that way.

+4


source







All Articles