How to: Determine if a File is Read-only in Visual Basic

The GetFileInfo method can be used to get a FileInfo object, which contains information about the specified file.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

To determine if a file is read-only

  • Use the GetFileInfo method to return a FileInfo object for the file, which can be queried for information. This example gets a FileInfo object for Testfile.txt and displays the appropriate message if the IsReadOnly property is set to True.

    Dim infoReader As System.IO.FileInfo
    infoReader = My.Computer.FileSystem.GetFileInfo("C:\testfile.txt")
    If infoReader.IsReadOnly = True Then
        MsgBox("File is readonly!")
    End If
    

See Also

Tasks

How to: Determine if a Directory is Read-Only in Visual Basic

Reference

FileSystem

GetFileInfo

Other Resources

File, Directory, and Drive Properties in Visual Basic