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

Piumi ganegoda
  • 163
  • 3
  • 12
  • 1
    Does this answer your question? [Cannot open local file - Chrome: Not allowed to load local resource](https://stackoverflow.com/questions/39007243/cannot-open-local-file-chrome-not-allowed-to-load-local-resource) – Jax-p Mar 11 '22 at 09:08
  • Thanks @Jax-p this didn't resolve the problem – Piumi ganegoda Mar 11 '22 at 09:14

1 Answers1

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

Alain Boudard
  • 768
  • 6
  • 16
  • any workaround to make the local folders accessible? – Piumi ganegoda Mar 11 '22 at 10:25
  • 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. https://web.dev/read-files/ – Alain Boudard Mar 11 '22 at 10:28