This documentation is archived and is not being maintained.

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

The My.Computer.FileSystem.GetFileInfo Method can be used to get a FileInfo object, which contains information about the specified file.

NoteNote:

  The options available in dialog boxes, and the names and locations of menu commands you see, might differ from what is described in Help, depending on your active settings or edition. This Help page was written with General Development Settings in mind. To change your settings, choose Import and Export Settings on the Tools menu. 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
    
Show: