Equivalent of File.ReadLines(filepath) C# in Javascript
NickName:JPaulPunzalan Ask DateTime:2017-03-30T10:52:34

Equivalent of File.ReadLines(filepath) C# in Javascript

In my current C# code, I used the .NET package File.ReadLines(). Are there any ways to re-write that code in Javascript?

var csvArray = File.ReadLines(filePath).Select(x => x.Split(',')).ToArray();

I know that LINQ Select could be used in Javascript. My current progress is on reading a CSV file. Kindly check my JS code below.

    var fs = require('fs');
    var csv = require('fast-csv');
    var filepath = $('#appFilePathInput').value();

    fs.createReadStream(filepath)
    .pipe(csv())
    .on('data', function(data){
        //Should I put the LINQ Select and Split toArray code here?
    });
    .on('data', function(data){
        console.log('Read Finished');
    });

GOAL is to read the local CSV file to an Array in JavaScript.

Kindly help me improve my existing code since it is my first time writing code in pure Javascript.

Thank you very much!

Copyright Notice:Content Author:「JPaulPunzalan」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/43107658/equivalent-of-file-readlinesfilepath-c-sharp-in-javascript

More about “Equivalent of File.ReadLines(filepath) C# in Javascript” related questions

Equivalent of File.ReadLines(filepath) C# in Javascript

In my current C# code, I used the .NET package File.ReadLines(). Are there any ways to re-write that code in Javascript? var csvArray = File.ReadLines(filePath).Select(x => x.Split(',')).ToArra...

Show Detail

Substitute File.Readlines() with something that is able to read URL/https

I'm trying to parse a .csv file located in Azure blob storage. When I parse the .csv file from my local using File.Readlines(), it works fine. When I pass the path of the blob and debug, I get the

Show Detail

Is File.ReadLines buffering read lines?

I have a very long text file (about 600MB of text) which I want to parse line by line. I can simply use StreamReader.ReadLine() method, but I'd like to know if using LINQ with File.ReadLines(filepa...

Show Detail

IEnumerable.Take(0) on File.ReadLines seems not to dispose/close the File handle

I have a function which Skips n lines of code and Takes y lines from a given file using File.ReadLines with Skip and Take combination. When I try to open the file given by filePath the next time: ...

Show Detail

Is there any way to take a specific group of lines using File.ReadLines?

I'm trying to grab every line after the first 2 lines in a text file and place them into a string. what i have so far is Count = File.ReadLines(filepath).Count(); String Lines = File.ReadLines(

Show Detail

Why File.ReadLines() in C# allocates too much memory?

I have twenty 10MB txt files and would like to read these files. I have read this, which says File.ReadLines() doesn't load entire lines so it doesn't spend much memory. var directory = "path/to/

Show Detail

Setting filepath to reference a file at the root of the Solution or Project

I want someone to just be able to fire up my solution, and in the Program have it run and just put this csv at the root of the project for example so that it just picks it up in my method that's go...

Show Detail

File.ReadLines "Can't Read From Closed TextReader"

I have been getting a wierd excepction that i am not sure what is causing it. In my local machine when i use: var lines = File.ReadLines("filePath"); foreach(string line in lines)... This works

Show Detail

C# Filepath Recasing

I'm trying to write a static member function in C# or find one in the .NET Framework that will re-case a file path to what the filesystem specifies. Example: string filepath = @"C:\temp.txt"; fil...

Show Detail

Filepath validation in Visual C

I have an unmanaged Win32 project in Visual studio. It is using only C language. For a function, I am getting a parameter as 'filepath'. I have to validate filepath. A test case will be written wh...

Show Detail