File Directory Dialog Box

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

    File Directory Dialog Box

    Is there a way in Javascript to bring up dialog boxes for both opening and
    then also saving a file?

  • kaeli

    #2
    Re: File Directory Dialog Box

    In article
    <968a10dc5a2a12 4c05fbb2afe9042 3ba@localhost.t alkaboutprogram ming.com>,
    rphipps@nospam. indy.rr.com enlightened us with...[color=blue]
    > Is there a way in Javascript to bring up dialog boxes for both opening and
    > then also saving a file?
    >[/color]

    Please clarify the question.
    What file is being opened?
    What do you mean by 'dialog box'? A prompt? A window? A "browse" button? A
    modal dialog window?

    What do you mean by "and then also"? Same button/prompt/whatever does both
    tasks? A dialog box for both tasks, but the dialog box is not the same
    object?


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



    Comment

    • rockocubs

      #3
      Re: File Directory Dialog Box

      This is going to be a file compare program. I just need to have the
      standard windows open file dialog box open so the user can select the
      file, i will use this twice so they can choose the two file's to be
      compared. After the compare i want the standard windows save as box to
      appear so they can save the results file.

      Comment

      • phil_gg04@treefic.com

        #4
        Re: File Directory Dialog Box

        > I just need to have the[color=blue]
        > standard windows open file dialog box open so the user can select the
        > file, I will use this twice so they can choose the two files to be
        > compared. After the compare I want the standard windows save as box[/color]
        to[color=blue]
        > appear so they can save the results file.[/color]

        In general, Javascript cannot read or write files from the local
        filesystem.

        You can create an "open" dialog by creating an <input type="file"> form
        element and could probably open it by invoking its onclick method
        (though I haven't tried it). But I don't think that the content of the
        selected file is available to Javascript (again, I haven't tried).
        Similarly a server-side implementation can trigger a "save as" and/or
        "open with" dialog by returning content of a type that the browser
        cannot handle natively, but I don't believe there is a way for
        Javascript to generate such content.

        I would be curious to know if anyone can suggest a way of doing this.

        --Phil.

        Comment

        • rockocubs

          #5
          Re: File Directory Dialog Box

          I dont plan on having the browser open and doing this in an html page, i
          guess i was assuming you could run javascript by itself like vbscript

          Comment

          • kaeli

            #6
            Re: File Directory Dialog Box

            In article <4d7cc225a92f00 1ec7ced86507ade bc5
            @localhost.talk aboutprogrammin g.com>, rphipps@nospam. indy.rr.com enlightened
            us with...[color=blue]
            > This is going to be a file compare program. I just need to have the
            > standard windows open file dialog box open so the user can select the
            > file, i will use this twice so they can choose the two file's to be
            > compared. After the compare i want the standard windows save as box to
            > appear so they can save the results file.
            >
            >[/color]

            The file input type prompts for a file on button click.
            <input type="file">

            For saving the results, I believe this would work. (Windows / MSIE only?)
            document.execCo mmand('SaveAs') ;

            If this is running on a PC, you may want to look into using an HTA with
            Windows Script Host. You don't tend to run into as many security problems
            that way. You get more stuff to play with, too. Check out FileSystemObjec t.

            HTH
            --
            --
            ~kaeli~
            Abdicate (v.), to give up all hope of ever having a flat
            stomach.



            Comment

            • runonthespot

              #7
              Re: File Directory Dialog Box

              You can.. as an HTA application.
              HTA gets a lot of bad press because it's an obvious tool for virus
              writers, but it effectively allows you to write an HTML application
              that lives outside the Browser sandbox. If you're not looking to put
              it online, and need a rapid dev environment, it's ideal. I've used it
              to produce simple applications before that leverage the easy displaying
              power of HTML, to be run from a local pc or over a network. Obviously
              all your code is visible, so not recommended for anything that requires
              security.

              Also, because it's out of the sandbox, you can do all manner of loading
              and saving files using the standard FileSystemObjec t (or any other Com
              type stuff).

              Comment

              • rockocubs

                #8
                Re: File Directory Dialog Box

                Where can i get information on HTA.

                Comment

                • runonthespot

                  #9
                  Re: File Directory Dialog Box

                  Kind of hard to find definitive guides to all it's uses, but
                  Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

                  gives you an overview. Basically it's an HTML file, saved as .HTA, run
                  using MSHTA.exe (in windows path).
                  Think it only really needs some sort of rudimentary tag in the head
                  like
                  <HTA:APPLICATIO N ID="oHTA"
                  APPLICATIONNAME ="MyApp"[color=blue]
                  >
                  >From there just build HTML as usual. I keep my scripts in a seperate[/color]
                  ..js file, linked in.

                  It's sometimes hard to find Javascript syntax for things like
                  FileSystemObjec t, but the info is out there on the web. Takes some time
                  to find, and if you are familiar with the VB versions, it doesn't
                  require much altering.

                  You could of course write the HTA using VBScript...

                  Comment

                  • rockocubs

                    #10
                    Re: File Directory Dialog Box

                    I have coded the open dialog in vbscript but couldn't find the save as, as
                    vbscript is the preferred method for the client.

                    Comment

                    • Lasse Reichstein Nielsen

                      #11
                      Re: File Directory Dialog Box

                      "rockocubs" <rphipps@nospam .indy.rr.com> writes:

                      (please remember to include *some* context for your posting)
                      [color=blue]
                      > I dont plan on having the browser open and doing this in an html page, i
                      > guess i was assuming you could run javascript by itself like vbscript[/color]

                      You can. On Windows-boxes, you can use any language supported by the
                      Windows Scripting Host. E.g., make a file called "test.js" containing:

                      alert("this works!");

                      and run it with "wscript test.js".

                      However, Javascript itself has no method of working with files, or any
                      other I/O for that matter. All of that is provided by the environment
                      the script is run in. The environment in browsers is the one assumed
                      by people in this group unless something else is stated.

                      If you run your scripts using "wscript", you should consult the
                      documentation for the Windows Scripting Host to find out what features
                      are available.

                      /L
                      --
                      Lasse Reichstein Nielsen - lrn@hotpop.com
                      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                      'Faith without judgement merely degrades the spirit divine.'

                      Comment

                      • Grant Wagner

                        #12
                        Re: File Directory Dialog Box

                        "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
                        news:wtr5urgj.f sf@hotpop.com.. .[color=blue]
                        > "rockocubs" <rphipps@nospam .indy.rr.com> writes:
                        >
                        > (please remember to include *some* context for your posting)
                        >[color=green]
                        >> I dont plan on having the browser open and doing this in an html
                        >> page, i
                        >> guess i was assuming you could run javascript by itself like vbscript[/color]
                        >
                        > You can. On Windows-boxes, you can use any language supported by the
                        > Windows Scripting Host. E.g., make a file called "test.js" containing:
                        >
                        > alert("this works!");
                        >
                        > and run it with "wscript test.js".[/color]

                        And get the error:
                        Script: \path\test.js
                        Line: 1
                        Char: 1
                        Error: Object expected
                        Code: 800A138F
                        Source: Microsoft JScript runtime error
                        [color=blue]
                        > However, Javascript itself has no method of working with files, or any
                        > other I/O for that matter. All of that is provided by the environment
                        > the script is run in. The environment in browsers is the one assumed
                        > by people in this group unless something else is stated.[/color]

                        The error encountered above is precisely because of this fact. alert()
                        is a method provided by the default global object to scripts executing
                        in Internet Explorer. alert() is not a method available to scripts
                        running in wscript/cscript because the host does not expose/provide such
                        a method.

                        To popup a dialog in wscript, you'd use:

                        WScript.Echo("t his works!");

                        (note this echos to the console when the script is executed with cscript
                        test.js).

                        To have a version that does the equivlent of alert() for both wscript
                        and cscript, you'd use:

                        var wshShell = new ActiveXObject(' WScript.Shell') ;
                        wshShell.Popup( "this works!");
                        [color=blue]
                        > If you run your scripts using "wscript", you should consult the
                        > documentation for the Windows Scripting Host to find out what features
                        > are available.[/color]

                        Indeed.

                        For relatively clean list of available WSH objects, properties and
                        methods, I prefer <url:
                        http://www.devguru.com/Technologies/...h_objects.html />

                        All the objects available there are instatiated (with the exception of
                        TextStream, which is returned by the StdErr, StdIn and StdOut properties
                        of the WScript object) in JScript using:

                        var wshWhatever = new ActiveXObject(' WScript.Whateve r');

                        There are also all sorts of other ActiveXObjects which are available
                        from WSH, such as the FileSystemObjec t <url:
                        Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

                        />

                        Note that these references are in no way intended to be a complete list
                        of references, only a sample of the types of references available on the
                        Web. Other references can be obtained by using Google to search for
                        something like:

                        "<object you are interested in> activexobject site:microsoft. com"

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


                        Comment

                        • Ramesh Nair

                          #13
                          Re: File Directory Dialog Box





                          *** Sent via Developersdex http://www.developersdex.com ***

                          Comment

                          Working...