Javascript FileSystemObject (FSO) textstream object’s Line property returns the current line number of the character being read by the textstream pointer while reading the textstream of the specified text file. Line property of textstream object also works in both FileReading as well as FileWriting mode. Line property starts from 1 and keeps on increasing while adding text lines into the specified file. 

Syntax for Javascript FSO textstream Line property

textStreamObj.Line;

textStreamObj can be initialized using FileSystemObject and its OpenTextFile method that will return the textstream retrieved from the specified text file.

Example of FSO textstream object Line property

<script type="text/javascript">
    // initialize ActiveXObject and create an object of Scripting.FileSystemObject.
    var fso = new ActiveXObject("Scripting.FileSystemObject");

    // Open the text file at the specified location with write mode
    var txtFile = fso.OpenTextFile("C:\\Temp\\myFolder\\file.txt", 2, false, 0);
    txtFile.WriteLine("Hello this is the first line of text file.");
    txtFile.WriteLine("Hello this is the second line of text file.");
    txtFile.WriteLine("Hello this is the third line of text file.");

    // return the line number while writing into the text file.
    document.write(txtFile.Line);
    txtFile.Close();

    // Open the text file at the specified location with read mode
    txtFile = fso.OpenTextFile("C:\\Temp\\myFolder\\file.txt", 1, false, 0);

    var text;

    // reads the specified number of characters of the text file
    text = txtFile.Read(52);
    document.write("<pre>" + text + "</pre>");
    document.write("<br />");

    // returns the line number while reading the specified text file.
    document.write(txtFile.Line);

    txtFile.Close();
    fso = null

    // Output: 4 
    // Hello this is the first line of text file. Hello th 
    // 2
</script>

Continue to next tutorial: Javascript FSO textstream File Close Method to learn how to close the textstream.

Recent JavaScript Tutorials

Javascript FSO ShortPath property

Javascript FileSystemObject (FSO) provides a ShortPath property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Path Property

Javascript FileSystemObject (FSO) provides the Path property that can be accessed through the file object or folder object returned by the GetFile or GelFolder method

Javascript FSO Type property

Javascript FileSystemObject (FSO) provides a Type property that can be accessed through file object or folder object returned by the GetFile or GetFolder method

Javascript FSO ShortName property

Javascript FileSystemObject (FSO) provides a ShortName property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Name Property

Javascript FileSystemObject (FSO) provides a Name property that can be accessed using file object or folder object.