Search code examples
vb.netpdfopenfiledialog

vb.net i can't choose pdf files


in vb.net, i create a simple method where i choose and see a (pdf and image files) , i used fileopendialog this is my code

Private Sub btn_parcour_Click(sender As Object, e As EventArgs) Handles btn_parcour.Click
    fichier.Filter = "PDF Files |* .pdf "
    If fichier.ShowDialog = DialogResult.OK Then
        fichier_txt.Text = fichier.FileName
    End If
End Sub

but when i open file dialog for To choose the file , i can't do it because , the message is you don't have a file

this is a screen

enter image description here


Solution

  • There are too many spaces in the filter. It will throw off the pattern matching.

    'Remove all the extra spaces
    fichier.Filter = "PDF Files|*.pdf"
    

    For example if doing pdf and all other files

    'Note no stray spaces where they are not needed
    fichier.Filter = "PDF Files|*.pdf|All files(*.*)|*.*"