Remote FileSystemObjects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Malcolm

    Remote FileSystemObjects

    I am a near total novice, trying to write some Javascript code that will
    display certain elements in a comma separated value file (gifts.csv) in
    tabular form when a page is loaded. I have come up with the following which
    works fine when I view the page in my coding tool (AceHTML 5 Pro). Basically
    it sets up an array, opens the csv file, reads each line from the file,
    decides whether the line needs processing and if so loads each value into an
    element of the array and writes some of them out. There are some table tags
    thrown into appropriate places.

    <script>

    information = new Array(10);
    y = new ActiveXObject(" Scripting.FileS ystemObject");
    gift = y.opentextfile( "gifts.csv" ,1);
    x = document.write( "<table>");

    do {
    x = document.write( "<tr>");
    giftinfo = gift.readline() ;

    if (giftinfo.charA t(0)=="0") {
    information = giftinfo.split( ",");
    x = document.write( "<td>",informat ion[4],"</td>");
    x = document.write( "<td>",informat ion[5],"</td>");
    x = document.write( "<td>",informat ion[9],"</td>");
    x = document.write( "</tr>");
    }
    }
    while (!gift.AtEndOfS tream);

    x = document.write( "</table>");

    </script>

    However it doesn't work from a server using IE. From what I've read I
    believe it is because the filesystemobjec t works with the local filesystem
    whereas the csv file is on the server.

    Is there any way of redoing this so that the file on the server is opened
    and read, or can I download the csv file onto the client machine so that it
    works as written, or do I need to be doing something with asp (is that
    right?) so the the scripting runs on the server not the client?

    Or am I asking the wrong questions?



  • Grant Wagner

    #2
    Re: Remote FileSystemObjec ts

    Malcolm wrote:
    [color=blue]
    > However it doesn't work from a server using IE. From what I've read I
    > believe it is because the filesystemobjec t works with the local filesystem
    > whereas the csv file is on the server.[/color]

    Correct.
    [color=blue]
    > Is there any way of redoing this so that the file on the server is opened
    > and read,[/color]

    Not really.
    [color=blue]
    > or can I download the csv file onto the client machine so that it
    > works as written,[/color]

    Nope.
    [color=blue]
    > or do I need to be doing something with asp (is that
    > right?)[/color]

    Well, it can solve your problem, but not the way you are trying to solve it now.
    [color=blue]
    > so the the scripting runs on the server not the client?[/color]

    No.
    [color=blue]
    > Or am I asking the wrong questions?[/color]

    Basically. You can't "open and read" an http resource. What you *can* do is load
    it into a hidden <iframe>, then parse the results using client-side JavaScript.
    You could also use the XML HTTP Request object <url:
    http://jibbering.com/2002/4/httprequest.html /> to request and parse the .csv
    file.

    However, the easiest thing to do is have ASP generate client side JavaScript
    that sets things up the way you want:

    <%
    // read the file
    // Response.write something that outputs the code shown below:
    // <script type="text/javascript">
    // var theCSVFile = [
    // [ row1value1, row1value2, row1value3 ],
    // [ row2value1, row2value2, row2value3 ],
    // // etc
    // ];
    // </script>
    %>

    --
    Grant Wagner <gwagner@agrico reunited.com>
    comp.lang.javas cript FAQ - http://jibbering.com/faq

    Comment

    Working...