-2

When i use openfiledialog.Filter somthing goes wrong. Here's my code:

openFileDialog1.Filter = "Video and Music Files (*.asf, *.wma, *.wmv, *.wm, *.asx, *.wax, *.wvx, *.wmx, *.wpl, *.dvr-ms, *.wmd, *.avi, *.mpg, *.mpeg, *.m1v, *.mp2, *.mp3, *.mpa, *.mpe, *.m3u, *.mid, *.midi, *.rmi. *.aif, *.aifc, *.aiff, *.au, *.snd, *.wav, *.cda, *.ivf, *.wmz, *.wms, *.mov, *.m4a, *.mp4, *.m4v, *.mp4v, *.3g2, *.3gp2, *.3gp, *.3gpp, *.aac, *.adt, *.adts, *.m2ts)|*.asf *.wma *.wmv *.wm *.asx *.wax *.wvx *.wmx *.wpl *.dvr-ms *.wmd *.avi *.mpg *.mpeg *.m1v *.mp2 *.mp3 *.mpa *.mpe *.m3u *.mid *.midi *.rmi *.aif *.aifc *.aiff *.au *.snd *.wav *.cda *.ivf *.wmz *.wms *.mov *.m4a *.mp4 *.m4v *.mp4v *.3g2 *.3gp2 *.3gp *.3gpp *.aac *.adt *.adts *.m2ts|All Files (*.*)|*.*"
Ewan
  • 11
  • 1

2 Answers2

4

Idle_Mind has it right below, you're missing the semicolons:

openFileDialog1.Filter = "Video and Music Files (*.asf, *.wma, *.wmv, *.wm, *.asx, *.wax, *.wvx, *.wmx, *.wpl, *.dvr-ms, *.wmd, *.avi, *.mpg, *.mpeg, *.m1v, *.mp2, *.mp3, *.mpa, *.mpe, *.m3u, *.mid, *.midi, *.rmi. *.aif, *.aifc, *.aiff, *.au, *.snd, *.wav, *.cda, *.ivf, *.wmz, *.wms, *.mov, *.m4a, *.mp4, *.m4v, *.mp4v, *.3g2, *.3gp2, *.3gp, *.3gpp, *.aac, *.adt, *.adts, *.m2ts)|*.asf; *.wma; *.wmv; *.wm; *.asx; *.wax; *.wvx; *.wmx; *.wpl; *.dvr-ms; *.wmd; *.avi; *.mpg; *.mpeg; *.m1v; *.mp2; *.mp3; *.mpa; *.mpe; *.m3u; *.mid; *.midi; *.rmi. *.aif; *.aifc; *.aiff; *.au; *.snd; *.wav; *.cda; *.ivf; *.wmz; *.wms; *.mov; *.m4a; *.mp4; *.m4v; *.mp4v; *.3g2; *.3gp2; *.3gp; *.3gpp; *.aac; *.adt; *.adts; *.m2ts|All Files (*.*)|*.*"    

The OpenDialog.Filter property is a bit nasty. It uses a pipe separator between alternating pairs of values like this:

openFileDialog1.Filter = "option 1|rules for option 1|option 2|rules for option 2|..."    

http://msdn.microsoft.com/en-us/library/system.windows.controls.openfiledialog.filter(v=vs.95).aspx

Derek Tomes
  • 3,989
  • 3
  • 27
  • 41
1

You need to separate the actual filters with semi-colons like:

*.abc;*.xyz;*.txt

The entries are in pairs. The first part is the description and be formatted however you like. The second part is the list of filters separated by semi-colons. The first and second parts are separated by the pipe symbol |.

Each set of pairs is also separated by pipe symbols.

The example in the docs is pretty good:

Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*

Specifically, your filter should look like:

OpenFileDialog1.Filter = "Video and Music Files (*.asf, *.wma, *.wmv, *.wm, *.asx, *.wax, *.wvx, *.wmx, *.wpl, *.dvr-ms, *.wmd, *.avi, *.mpg, *.mpeg, *.m1v, *.mp2, *.mp3, *.mpa, *.mpe, *.m3u, *.mid, *.midi, *.rmi. *.aif, *.aifc, *.aiff, *.au, *.snd, *.wav, *.cda, *.ivf, *.wmz, *.wms, *.mov, *.m4a, *.mp4, *.m4v, *.mp4v, *.3g2, *.3gp2, *.3gp, *.3gpp, *.aac, *.adt, *.adts, *.m2ts)|*.asf;*.wma;*.wmv;*.wm;*.asx;*.wax;*.wvx;*.wmx;*.wpl;*.dvr-ms;*.wmd;*.avi;*.mpg;*.mpeg;*.m1v;*.mp2;*.mp3;*.mpa;*.mpe;*.m3u;*.mid;*.midi;*.rmi;*.aif;*.aifc;*.aiff;*.au;*.snd;*.wav;*.cda;*.ivf;*.wmz;*.wms;*.mov;*.m4a;*.mp4;*.m4v;*.mp4v;*.3g2;*.3gp2;*.3gp;*.3gpp;*.aac;*.adt;*.adts;*.m2ts|All Files (*.*)|*.*"
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40