0

I have an angular app. When I try to open a text file from a new window in a local folder(F drive) on button click, console log the below error. Any suggestion to fix this and open it.

 clickme(){
    window.open("F:/Angular repo/New Text Document.txt", "_blank");                           
     }

enter image description here

2

1 Answer 1

1

you cannot open such a file from a web page that is hosted on a "server" (wether your Angular app is served with ng serve command or with a web server like nginx). You would need to upload it somewhere, and it will have an URL on its own :

- http://my-server/my-file.txt

Or you can place this file in the /assets folder of your Angular application, if you intend to deliver this file along with your Angular pages.

Maybe you can check such articles about assets in Angular : https://lukasznojek.com/blog/2019/03/angular-cli-different-ways-to-include-assets/

Cheers

Sign up to request clarification or add additional context in comments.

2 Comments

any workaround to make the local folders accessible?
Well, this is not related to Angular really, so I would advice you to check on your objectives, what exactly do you want to do with this file, does it really have to be on the disk ... and so on. If you really want to access it, you would have to make a input type file in HTML form and use the FileAPI to read it eventually. web.dev/read-files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.