We help IT Professionals succeed at work.

How do I set file permissions to access all files on my local computer?

KarlTheHopeless used Ask the Experts™
The program below fails because, it seems, that I do not have the correct permissions to access the files on my local computer - and the FileOpen method requires that I have the appropriate permissions.


Dim tem As String = ""
        tempno = FreeFile()
        FileOpen(tempno, "c:\myvbastext\listoffilesandpaths.txt", OpenMode.Input)
        i% = 0
        While Not EOF(tempno)
            i% = i% + 1
            Input(tempno, tem)

                   End While


The error message is "Late bound calls to file system methods in the Visual Basic runtime are not permitted." and the error is described as a "SecurityException was unhandled."

Can someone please tell me exactly how to set the file permissions correctly so that I can access the file mentioned above - as well as all other files on my computer.

Thank you.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010
You can use the FileStream Class to specify access rights.

Dim fStream As New FileStream("c:\myvbastext\listoffilesandpaths.txt", FileMode.Open, FileAccess.Read, FileShare.Read, 65536)
        Dim sReader As New StreamReader(fStream)

        '// Read a single lines from the text file.


Open in new window



It worked. Thank you.

But the VB Error Message kept telling me that I had a File Permission problem and/or a 'Full Trust' problem; and I have spent ages going down that track -  and getting nowhere.

And I have just discovered that the INPUT method used in my code above was wrong - and that I should have used the LINEINPUT method.

In other words, the VB Error Message was totally inappropriate and misleading.

Ho Hum. Only about six hours wasted.