Reading a file

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

    #1

    Reading a file

    OK, I know I can't read a file with JavaScript, but I see references
    that I can use the filesystemobjec t which is part of vb script. Can I
    embed vb script in HTML?

    I am writing a program for company internal use that will extract
    information from a drawing on the user's local workstation and then
    needs to convey that information to a web app communicating to the
    user through their brower. Everything is pretty much microsoft tho'
    we don't use IIS but are using the web serving capabilities of
    weblogic.

    Any suggestions for how to get that file's contents (probably less
    than 1K) into the web app would be greatly appreciated. I don't mind
    doing some digging here but point me in the right direction, please.

    TIA

    Steve
  • MikeB

    #2
    Re: Reading a file


    "Steve" <swl773@hotZmai l.com> wrote in message news:mqtja0llah c4c3eua6pc22b7i r2hhel8ib@4ax.c om...[color=blue]
    > OK, I know I can't read a file with JavaScript, but I see references[/color]

    Not true. The FileSystemObjec t is availabel to JScript and JavaScript, instantiated as an ActiveX
    object. For Internal use, look at putting your code in an HTA to avoid the Security constraints imposed
    by the browser environment.
    [color=blue]
    > that I can use the filesystemobjec t which is part of vb script. Can I
    > embed vb script in HTML?
    >
    > I am writing a program for company internal use that will extract
    > information from a drawing on the user's local workstation and then
    > needs to convey that information to a web app communicating to the
    > user through their brower. Everything is pretty much microsoft tho'
    > we don't use IIS but are using the web serving capabilities of
    > weblogic.
    >
    > Any suggestions for how to get that file's contents (probably less
    > than 1K) into the web app would be greatly appreciated. I don't mind
    > doing some digging here but point me in the right direction, please.
    >
    > TIA
    >
    > Steve[/color]


    Comment

    • kaeli

      #3
      Re: Reading a file

      In article <mqtja0llahc4c3 eua6pc22b7ir2hh el8ib@4ax.com>, swl773
      @hotZmail.com enlightened us with...[color=blue]
      > OK, I know I can't read a file with JavaScript, but I see references
      > that I can use the filesystemobjec t which is part of vb script. Can I
      > embed vb script in HTML?[/color]

      Yes, but only IE understands it. I prefer JScript, and this is a
      javascript group after all. JScript is also IE only. (It may work with
      javascript, too, but I didn't check)
      [color=blue]
      >
      > I am writing a program for company internal use that will extract
      > information from a drawing on the user's local workstation and then
      > needs to convey that information to a web app communicating to the
      > user through their brower. Everything is pretty much microsoft tho'
      > we don't use IIS but are using the web serving capabilities of
      > weblogic.[/color]

      The server is irrelevant for reading client-side files.
      [color=blue]
      >
      > Any suggestions for how to get that file's contents (probably less
      > than 1K) into the web app would be greatly appreciated. I don't mind
      > doing some digging here but point me in the right direction, please.
      >[/color]

      The following reads a text file from the user's (client) machine with
      JScript and writes the contents to a div. Watch for word-wrap.
      [note that the following generates an ActiveX warning]

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
      "http://www.w3.org/TR/REC-html40/loose.dtd">
      <html>
      <head>
      <title> Read client file with JScript </title>
      </head>

      <body>
      <script language="JScri pt" type="text/jscript">

      function ReadFile(filena me)
      {
      var fso, f;
      var ForReading = 1;
      fso = new ActiveXObject(" Scripting.FileS ystemObject");

      f = fso.OpenTextFil e(filename,
      ForReading);
      txtbox.innerTex t = f.ReadAll();
      f.close()
      }

      </script>
      <BUTTON style="border: 1px outset; width:100px" onClick="ReadFi le('c:
      \\test.txt');">
      Read File</BUTTON>
      <div id="txtbox"></div>
      </body>
      </html>

      I made a simple text file and saved it to c:\\test.txt.
      Contents of text.txt:
      this is a test file
      with some contents in it
      for testing
      file IO

      --
      --
      ~kaeli~
      Is it true that cannibals don't eat clowns because they
      taste funny?



      Comment

      Working...