3 Replies Latest reply on Jan 27, 2010 12:50 PM by olegkon

    Browse to create file

    olegkon Level 1

      Hi,

       

      I am writing AIR 1.5 app, which emulates Excel 2007.

       

      Silly question: 

      if I need to browse to create a new file, how do I do it ?

      I tried file.browse, browseForOpen, browseForSave...  they all require for file to exist already.

       

      So what do I do if it doesn't exist, I am creating a new file (to save the context of DataGrid into XLSX file.

       

      I am using Java POI framework to read/write files via Web Service.

       

       

      TIA,

      Oleg.

        • 1. Re: Browse to create file
          olegkon Level 1

          I forgot to mention:

          - it is supposed to work on local hard disk;

          - so AIR app is supposed to browse to directory, create a file

          and pass a file's native path to Java via Web service to open that file & save data there

          - I use Tomcat6 & Axis 1.4 for web service.

           

          Thank you,

          Oleg.

          • 2. Re: Browse to create file
            heavyboots Level 2

            Essentially, I think you want the user to do browseForDirectory? If you actually want them to save with a filename, that will be the browseForSave, but if you're just trying to choose the path to save into browseForDirectory is probably the winner.

             

            From the AIR online manual:

             

            Letting the user browse to select a directory


            The File class includes the browseForDirectory()
            method, which presents a system dialog box in which the user can select a
            directory to assign to the object. The browseForDirectory() method is asynchronous. It dispatches a
            select event if the user selects a directory and
            clicks the Open button, or it dispatches a cancel
            event if the user clicks the Cancel button.


            For example, the following code lets the user select a directory and outputs
            the directory path upon selection:

            var file:File = new File(); 
            file.addEventListener(Event.SELECT, dirSelected); 
            file.browseForDirectory("Select a directory"); 
            function dirSelected(e:Event):void { 
                trace(file.nativePath); 
            }
            
            
            1 person found this helpful
            • 3. Re: Browse to create file
              olegkon Level 1

              Heavyboots,

               

              You are right:

              I should use File.createForSave to browse to create a new file (to save data later).

              I needed full nativepath, incl. new file name to pass to Java.

               

              Sorry, had a bug in my code which prevented it from working correctly first time.

               

               

              Thanks,

              Oleg.