Results 1 to 6 of 6

Thread: JS: read a text file and output it

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Posts
    18

    Angry

    how can i read a plain text file then output it via document.write?

  2. #2
    Guest
    Hi....

    try the following sample code

    function GetEverything()
    {
    var fso, f;
    var ForReading = 1, ForWriting = 2;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    f = fso.OpenTextFile("c:\\testfile.txt", ForWriting, true);
    f.Write("Header");
    f.Write("1234567890987654321");
    f.Close();
    f = fso.OpenTextFile("c:\\testfile.txt", ForReading);
    document.write f.ReadAll
    return(f.ReadAll());
    }

    Regards,
    Mac

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Posts
    18
    does the OpenTextFile function require the absolute path of the file??

  4. #4
    Guest

    Cool

    Hi ...James..

    Sure it's need an absolute path ...

    u can use
    fso.GetAbsolutePathName(path)


    Regards,
    Mac


  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Posts
    18
    can this method read a file from the webserver or is it from the client machine?

    because i need a replacement for <!--#include file""> ssi.

  6. #6
    Guest
    Hi....
    Yes but u need to do as below..

    in ASP

    <%
    Set fso = Server.CreateObject("Scripting.FileSystemObject")

    then code goes here ....
    %>

    If for Client Side, in VBScript

    Set fso = CreateObject("Scripting.FileSystemObject")



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width