Skip to content

How to know no file was selected in OpenFileDialog?

Shahab

Asked Feb 18, 2013, 11:53 PM EST1 answer
Share
LinkedInX
Hi,

I want to use C# OpenFileDialog in my Windows Form application. How could I know if no files are selected ? I tried 

if (OpenFileDialog.FilesNames.Length == 0)

but it didnt work ...

Could you plz help me.

Thansk in advance.

Shahab.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    I tried now this combination & it works :

    Code
     if (dialog.ShowDialog() == DialogResult.OK)
        strFileName =  dialog.FileName;
     if (strFileName == String.Empty)
        return; //user didn't select a file to opena

    Thanks to auto-answer from Csharpcorner :-)
    0