Search code examples
c#winformsfilterwindows-10openfiledialog

Cannot filter pdfs and txt files in OpenFileDialog


I have been using this filter to filter pdfs and other files.

 ChooseDocumnetOfd.Filter = "Pdf files (*.pdf)|*.pdf |Office Files|*.doc;*.xls;*.ppt |Txt files (*.txt); *.txt | ";

It had been working well for a long time. However, I can only filter Word files now. Why can't I filter any other type of file now?


Solution

  • That's not a valid filter string; you're missing a pipe symbol after the Txt files entry, and there's an extraneous pipe at the end. It should look like this:

    ChooseDocumnetOfd.Filter = "Pdf files (*.pdf)|*.pdf|Office Files|*.doc;*.xls;*.ppt|Txt files (*.txt)|*.txt";