0

I am going through questions and I found the exact same problem I have but the question was never answered. The link to the question is:

javascript how to read a local file Dcnied access

Basically, I am logged in as Administrator and running Visual Studio as administrator and my local file is under the C:\users\Administrator directory and my code is the exact same code as link's post and I'm getting Access Denied. here is my code:

        function readTextFile(file) {
        var rawFile = new XMLHttpRequest();
        rawFile.open("GET", file, false);
        rawFile.onreadystatechange = function () {
            if (rawFile.readyState === 4) {
                if (rawFile.status === 200 || rawFile.status == 0) {
                    var allText = rawFile.responseText;
                    alert(allText);
                }
            }
        }
        rawFile.send(null);
    }

    function kmlBtnClick () {
        readTextFile("file:///c:/users/Administrator/KML/Operations.kml")

    }

Can anyone help?

3
  • Are you seeing the same error in all browsers? In chrome do you get a cross-origin-request error? Does adding localhost to trusted sites help? Commented Jan 3, 2020 at 20:17
  • 1
    The native file system is only available under the experimental flag.
    – DedaDev
    Commented Jan 3, 2020 at 20:33
  • Yes I am seeing the same browser error. Now as far as the experimental flag I'm not sure what your talking about.
    – holdorfs
    Commented Jan 3, 2020 at 20:56

1 Answer 1

1

this is the answer to this. Local file access with JavaScript

you can just create an input for file and select it there.

<input type="file">

Not the answer you're looking for? Browse other questions tagged or ask your own question.