Hi. I was just wondering if there is a simple way to detect if the filetype is a sort of docuemnt which can be read and written. e.g. txt, docx, ini ect. I want to make it in s uch a way that when the listview selects and item it will check those filetypes and if it's not a document then a button doesn't get enabled. If it is then the button does get enabled.

Anyone?
Thnks.

Recommended Answers

You'll probably have to create a list of file extensions and use the Contains method to see if the selected file's extension is in the list.

Jump to Post

All 3 Replies

You'll probably have to create a list of file extensions and use the Contains method to see if the selected file's extension is in the list.

You'll probably have to create a list of file extensions and use the Contains method to see if the selected file's extension is in the list.

Is there an example you could show me?

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Dim FileExtension As String = ".exe"
    If CheckExt(FileExtension) Then
        MessageBox.Show("True")
    Else
        MessageBox.Show("False")
    End If
End Sub
Dim Extensions As New List(Of String)({".txt", ".doc", ".rtf"})
Private Function CheckExt(pExtension As String) As Boolean
    Return Extensions.Contains(pExtension)
End Function
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.