Hi @Koray Genç , Welcome to Microsoft Q&A, you could try the following code to get what you wanted.
Because DLG. Filter is to filter out the displayed files. So an easy way to do this is to put the suffix you need to display.
OpenFileDialog dlg = new OpenFileDialog();
// Filter by Word Documents OR Excel Worksheets OR PowerPoint Presentations
// OR Office Files
// OR All Files
//dlg.Filter = "Word Documents|*.doc|Excel Worksheets|*.xls|PowerPoint Presentations|*.ppt" +
// "|Office Files|*.doc;*.xls;*.ppt" +
// "|All Files|*.*";
dlg.Filter = "All Files|*.doc;*.xls;*.ppt;*.doc;.xls;*.ppt;*.txt;";
dlg.ShowDialog();
Update:
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "All Files|*.*";
bool Flag = true;
while (Flag)
{
if (dlg.ShowDialog() == DialogResult.OK)
{
if (dlg.SafeFileName.Contains(".exe") | dlg.SafeFileName.Contains(".pdf"))
{
MessageBox.Show("This File Cannot Be Select");
dlg.FileName = "";
}
else
{
Flag = false;
}
}
else
{
MessageBox.Show("Select error");
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.