Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a file located at C drive.
I want to read contents of that file in anular 5.

What I have tried:

I am trying to use filereader in typescript .
However how to send file as a parameter from typescript ?
Posted
Updated 24-May-18 3:27am
Comments
AlwzLearning 24-May-18 1:34am    
Well I tried this:

this.file = new File(["Hello World"],"D:\Hello.txt",{type: "text/plain"})
console.log(this.file);
this.fileReader = new FileReader();
this.fileReader.onload = () => {
console.log(this.fileReader.result);
};
this.fileReader.readAsText(this.file);
console.log(this.fileReader);


However i am still looking to take filename. I am not sure how to provide filename.

1 solution

Websites cannot read random files from the user's disk. You can only read files which the user has explicitly given you access to, either by selecting them in an <input type="file">, or by dragging them into your application.

If the user hasn't selected the file, then your code cannot read it.

Using files from web applications - Web APIs | MDN[^]
 
Share this answer
 
Comments
AlwzLearning 24-May-18 12:53pm    
The issue I am running into is, Ansible is creating a log file and I have to show that log file into web application say like in some text area.

any guidance would help
Richard Deeming 24-May-18 12:55pm    
As I said, the user has to select the file. Your code cannot access any files on the user's computer unless the user selects the file first.
AlwzLearning 24-May-18 14:38pm    
Thank you for reply and sorry to bug you .
Well i have been a .net developer and angular is new to me.

So I am trying to understand , Microsoft provides system.io namespace which provides support with files and directories and i use streamreader/writer to read the contents of a file located at particular location.. Do I not have anything similar in Angular ?
Richard Deeming 24-May-18 15:02pm    
No. If websites were able to read files from your computer without you having to select them first, that would be a major security vulnerability.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900