javascript and write to text file

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

    javascript and write to text file

    Hi,
    I understand that for security and other reasons that javascript does
    not support writing/reading
    to text files. I am looking for a way that will however.
    This is what i am trying to do. I want to develop a simple html page
    that is run locally on a windows
    2000 box in IE. The page will have a browse button to select a source
    folder, either locally or a network
    computer on same lan. A destination folder, either locally or a network
    computer on same lan
    These two paths will be written to a text file.
    Then the page has two fields, A and B. Both A and B have their own
    'Add' Buttons. So I would
    enter a number into either field A or B and hit add.
    Then the whole form has a Reset and Submit Button. So once I was done
    entering all the data into
    all fields, I would hit submit and create a text file from it.
    I made this quickly to give an idea


    One thing i would like to do is display all the data I have entered,
    so once I select the Source folder,
    it displays on the page. Likewise with the data in Fields A and B once
    I add it.
    So the page may look like this

    It wouldn't have to look or behave just like this, but just a way for me
    to see what has been entered.

    so then it creates a text file and all the values need to be separated
    by a comma, so the end result
    would be
    data.txt
    -----------------------------------------------------------------------------------
    Source, F:\pictures\pho tos,
    Destination, \\Chuckwhite\c\ My Shared Folder,
    A, 394859, 493029, 584920, 938934, 843234, 839238, 950535, 3438595,
    349450, 239405, 839049,
    930499, 039483,
    B, 304893, 930984, 930945, 948404, 340594, 483920, 849302, 483920,
    849472, 138594, 039483,
    585048, 9302938, 893849, 9304849, 938403, 823940, 734892, 83749, 847433,
    -------------------------------------------------------------------------------------


    Any help or suggestions on how to do this is appreciated,
    Chuck

  • Fabian

    #2
    Re: javascript and write to text file

    chuck clark hu kiteb:
    [color=blue]
    > Hi,
    > I understand that for security and other reasons that javascript
    > does not support writing/reading
    > to text files. I am looking for a way that will however.[/color]

    Eh? I thought you just that you understood it to be impossible.


    --
    --
    Fabian
    Visit my website often and for long periods!


    Comment

    • Brian Genisio

      #3
      Re: javascript and write to text file

      chuck clark wrote:
      [color=blue]
      > Hi,
      > I understand that for security and other reasons that javascript does
      > not support writing/reading
      > to text files. I am looking for a way that will however.
      > This is what i am trying to do. I want to develop a simple html page
      > that is run locally on a windows
      > 2000 box in IE. The page will have a browse button to select a source
      > folder, either locally or a network
      > computer on same lan. A destination folder, either locally or a network
      > computer on same lan
      > These two paths will be written to a text file.
      > Then the page has two fields, A and B. Both A and B have their own
      > 'Add' Buttons. So I would
      > enter a number into either field A or B and hit add. Then the whole
      > form has a Reset and Submit Button. So once I was done entering all the
      > data into
      > all fields, I would hit submit and create a text file from it. I made
      > this quickly to give an idea
      > http://www.largeprojections.com/js/page1.htm
      >
      > One thing i would like to do is display all the data I have entered, so
      > once I select the Source folder,
      > it displays on the page. Likewise with the data in Fields A and B once
      > I add it.
      > So the page may look like this
      > http://www.largeprojections.com/js/page2.htm
      > It wouldn't have to look or behave just like this, but just a way for me
      > to see what has been entered.
      >
      > so then it creates a text file and all the values need to be separated
      > by a comma, so the end result
      > would be
      > data.txt
      > -----------------------------------------------------------------------------------
      >
      > Source, F:\pictures\pho tos,
      > Destination, \\Chuckwhite\c\ My Shared Folder,
      > A, 394859, 493029, 584920, 938934, 843234, 839238, 950535, 3438595,
      > 349450, 239405, 839049,
      > 930499, 039483,
      > B, 304893, 930984, 930945, 948404, 340594, 483920, 849302, 483920,
      > 849472, 138594, 039483,
      > 585048, 9302938, 893849, 9304849, 938403, 823940, 734892, 83749, 847433,
      > -------------------------------------------------------------------------------------
      >
      >
      >
      > Any help or suggestions on how to do this is appreciated,
      > Chuck
      >[/color]

      I know that Hyper Text Applications (HTA) allow you to override a lot of
      security features... and I _thought_ you could write files with it, but
      I am not sure. It only works with IE, but it sounds like that with your
      requirements, this might not be a problem.

      I know that MSDN has minimal documentation for the HTA technology. I
      also know that there are a few other platform-specific technologies that
      do this type of thing, but I cant think of them off the top of my head.
      They end up being extensions.

      Brian

      Comment

      • MikeB

        #4
        Re: javascript and write to text file


        "Brian Genisio" <BrianGenisio@y ahoo.com> wrote in message news:4003ea9a$1 @10.10.0.241...[color=blue]
        > chuck clark wrote:
        >[color=green]
        > > Hi,
        > > I understand that for security and other reasons that javascript does
        > > not support writing/reading
        > > to text files. I am looking for a way that will however.
        > > This is what i am trying to do. I want to develop a simple html page
        > > that is run locally on a windows
        > > 2000 box in IE. The page will have a browse button to select a source
        > > folder, either locally or a network
        > > computer on same lan. A destination folder, either locally or a network
        > > computer on same lan
        > > These two paths will be written to a text file.
        > > Then the page has two fields, A and B. Both A and B have their own
        > > 'Add' Buttons. So I would
        > > enter a number into either field A or B and hit add. Then the whole
        > > form has a Reset and Submit Button. So once I was done entering all the
        > > data into
        > > all fields, I would hit submit and create a text file from it. I made
        > > this quickly to give an idea
        > > http://www.largeprojections.com/js/page1.htm
        > >
        > > One thing i would like to do is display all the data I have entered, so
        > > once I select the Source folder,
        > > it displays on the page. Likewise with the data in Fields A and B once
        > > I add it.
        > > So the page may look like this
        > > http://www.largeprojections.com/js/page2.htm
        > > It wouldn't have to look or behave just like this, but just a way for me
        > > to see what has been entered.
        > >
        > > so then it creates a text file and all the values need to be separated
        > > by a comma, so the end result
        > > would be
        > > data.txt
        > > -----------------------------------------------------------------------------------
        > >
        > > Source, F:\pictures\pho tos,
        > > Destination, \\Chuckwhite\c\ My Shared Folder,
        > > A, 394859, 493029, 584920, 938934, 843234, 839238, 950535, 3438595,
        > > 349450, 239405, 839049,
        > > 930499, 039483,
        > > B, 304893, 930984, 930945, 948404, 340594, 483920, 849302, 483920,
        > > 849472, 138594, 039483,
        > > 585048, 9302938, 893849, 9304849, 938403, 823940, 734892, 83749, 847433,
        > > -------------------------------------------------------------------------------------
        > >
        > >
        > >
        > > Any help or suggestions on how to do this is appreciated,
        > > Chuck
        > >[/color]
        >
        > I know that Hyper Text Applications (HTA) allow you to override a lot of
        > security features... and I _thought_ you could write files with it, but
        > I am not sure. It only works with IE, but it sounds like that with your[/color]

        HTA DOES allow read/write to the local file system....

        Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

        [color=blue]
        > requirements, this might not be a problem.
        >
        > I know that MSDN has minimal documentation for the HTA technology. I
        > also know that there are a few other platform-specific technologies that
        > do this type of thing, but I cant think of them off the top of my head.
        > They end up being extensions.
        >
        > Brian
        >[/color]


        Comment

        • Laurent Bugnion, GalaSoft

          #5
          Re: javascript and write to text file

          Hi,

          Fabian wrote:
          [color=blue]
          > chuck clark hu kiteb:
          >
          >[color=green]
          >>Hi,
          >> I understand that for security and other reasons that javascript
          >>does not support writing/reading
          >>to text files. I am looking for a way that will however.[/color]
          >
          >
          > Eh? I thought you just that you understood it to be impossible.[/color]

          He never said it was impossible. He said that JavaScript does not
          support it, which is correct (at least client-side JavaScript). However,
          there are possibilities, using Java classes or ActiveX technology (which
          is not JavaScript, but which can be scripted).

          However, the security model of browsers often blocks this, at least in
          normal security conditions.

          Hereunder an example that I use with local HTML files or HTA applications.

          Laurent

          CExplorer.ALERT 001 = "This method works only in Netscape 4.* "
          + "and Internet Explorer";
          CExplorer.ALERT 002 = "The file already exists, overwrite?";
          CExplorer.ALERT 003 = "This method works only on Windows platforms.";

          CExplorer.saveT extFile = function( strFullPath, strContent, bOverwrite )
          {
          if ( ( navigator.appNa me != "Netscape" )
          && ( navigator.appNa me != "Microsoft Internet Explorer" ) )
          {
          alert( CExplorer.ALERT 001 );
          return;
          }

          if ( ( navigator.appNa me == "Netscape" )
          && ( parseFloat( navigator.appVe rsion ) >= 5 ) )
          {
          alert( CExplorer.ALERT 001 );
          return;
          }

          if ( navigator.platf orm.indexOf( "Win" ) == -1 )
          {
          alert( CExplorer.ALERT 003 );
          return;
          }

          if ( navigator.appNa me.indexOf( "Netscape" ) == -1 )
          {
          var fso = new ActiveXObject( "Scripting.File SystemObject" );

          if ( bOverwrite
          || !fso.FileExists ( strFullPath )
          || confirm( CExplorer.ALERT 002 ) )
          {
          var flOutput = fso.CreateTextF ile( strFullPath, true );
          flOutput.Write( strContent );
          flOutput.Close( );
          return true;
          }
          else
          {
          return false;
          }
          }
          else
          {
          netscape.securi ty.PrivilegeMan ager.enablePriv ilege(
          "UniversalFileR ead" );

          var flCheck = new java.io.File( strFullPath );

          if ( bOverwrite
          || !flCheck.exists ()
          || confirm( CExplorer.ALERT 002 ) )
          {
          netscape.securi ty.PrivilegeMan ager.enablePriv ilege(
          "UniversalFileW rite" );
          var fsOutput = new java.io.FileOut putStream( strFullPath );
          var flOutput = new java.io.DataOut putStream( fsOutput );

          flOutput.writeB ytes( strContent );

          flOutput.flush( );
          fsOutput.close( );
          return true;
          }
          else
          {
          return false;
          }
          }
          }


          --
          Laurent Bugnion, GalaSoft
          Software engineering: http://www.galasoft-LB.ch
          Private/Malaysia: http://mypage.bluewin.ch/lbugnion
          Support children in Calcutta: http://www.calcutta-espoir.ch

          Comment

          • Mark Szlazak

            #6
            Re: javascript and write to text file

            "Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin.ch> wrote in message news:<4007e61a$ 1_1@news.bluewi n.ch>...[color=blue]
            > Hi,
            >
            > Fabian wrote:
            >[color=green]
            > > chuck clark hu kiteb:
            > >
            > >[color=darkred]
            > >>Hi,
            > >> I understand that for security and other reasons that javascript
            > >>does not support writing/reading
            > >>to text files. I am looking for a way that will however.[/color]
            > >
            > >
            > > Eh? I thought you just that you understood it to be impossible.[/color]
            >
            > He never said it was impossible. He said that JavaScript does not
            > support it, which is correct (at least client-side JavaScript). However,
            > there are possibilities, using Java classes or ActiveX technology (which
            > is not JavaScript, but which can be scripted).
            >
            > However, the security model of browsers often blocks this, at least in
            > normal security conditions.
            >
            > Hereunder an example that I use with local HTML files or HTA applications.
            >
            > Laurent
            >
            > CExplorer.ALERT 001 = "This method works only in Netscape 4.* "
            > + "and Internet Explorer";
            > CExplorer.ALERT 002 = "The file already exists, overwrite?";
            > CExplorer.ALERT 003 = "This method works only on Windows platforms.";
            >
            > CExplorer.saveT extFile = function( strFullPath, strContent, bOverwrite )
            > {
            > if ( ( navigator.appNa me != "Netscape" )
            > && ( navigator.appNa me != "Microsoft Internet Explorer" ) )
            > {
            > alert( CExplorer.ALERT 001 );
            > return;
            > }
            >
            > if ( ( navigator.appNa me == "Netscape" )
            > && ( parseFloat( navigator.appVe rsion ) >= 5 ) )
            > {
            > alert( CExplorer.ALERT 001 );
            > return;
            > }
            >
            > if ( navigator.platf orm.indexOf( "Win" ) == -1 )
            > {
            > alert( CExplorer.ALERT 003 );
            > return;
            > }
            >
            > if ( navigator.appNa me.indexOf( "Netscape" ) == -1 )
            > {
            > var fso = new ActiveXObject( "Scripting.File SystemObject" );
            >
            > if ( bOverwrite
            > || !fso.FileExists ( strFullPath )
            > || confirm( CExplorer.ALERT 002 ) )
            > {
            > var flOutput = fso.CreateTextF ile( strFullPath, true );
            > flOutput.Write( strContent );
            > flOutput.Close( );
            > return true;
            > }
            > else
            > {
            > return false;
            > }
            > }
            > else
            > {
            > netscape.securi ty.PrivilegeMan ager.enablePriv ilege(
            > "UniversalFileR ead" );
            >
            > var flCheck = new java.io.File( strFullPath );
            >
            > if ( bOverwrite
            > || !flCheck.exists ()
            > || confirm( CExplorer.ALERT 002 ) )
            > {
            > netscape.securi ty.PrivilegeMan ager.enablePriv ilege(
            > "UniversalFileW rite" );
            > var fsOutput = new java.io.FileOut putStream( strFullPath );
            > var flOutput = new java.io.DataOut putStream( fsOutput );
            >
            > flOutput.writeB ytes( strContent );
            >
            > flOutput.flush( );
            > fsOutput.close( );
            > return true;
            > }
            > else
            > {
            > return false;
            > }
            > }
            > }[/color]


            You could add more branches and then use JavaScript via XPCOM to read
            or write to local files in Mozilla and Netscape 7. Check out the
            following link for details:


            Comment

            • Laurent Bugnion, GalaSoft

              #7
              Re: javascript and write to text file

              Hi Mark,

              Mark Szlazak wrote:
              [color=blue]
              > You could add more branches and then use JavaScript via XPCOM to read
              > or write to local files in Mozilla and Netscape 7. Check out the
              > following link for details:
              >
              > http://www.faqts.com/knowledge_base/...d/23360/fid/53[/color]

              Thanks a lot for that. I was looking for this kind of things, without
              having had the time to do a correct research and actually find the solution.

              Laurent
              --
              Laurent Bugnion, GalaSoft
              Software engineering: http://www.galasoft-LB.ch
              Private/Malaysia: http://mypage.bluewin.ch/lbugnion
              Support children in Calcutta: http://www.calcutta-espoir.ch

              Comment

              Working...