4 Replies Latest reply on Jul 13, 2011 5:12 AM by BaronKarza

    Open a Folder in Air 2.7

    BaronKarza Level 1

      Hello there,

      When Air 2.0 was released, it was possibile to do something like this (c:\mydirectory\mysubdirectory has to be there obviously):

       

      var file:File = new File("c:\\mydirectory\\mysubdirectory");

      file.openWithDefaultApplication();

       

      and the directory would be opened by using (for exampe) in windows the file explorer

       

      In air 2.7 this code throws an error (that is a security error, in fact if I open a temp directory created with createTempDirectory it works)

      "Illegal file path"

       

      Now, please, tell me how can I harm the user by simply opening a directory on his hard disk!

      How can I open a directory on his hard disk without getting this error?

      Thanks in advance

        • 1. Re: Open a Folder in Air 2.7
          Peter Blazejewicz Level 4

          Hi,

           

          I think that "Illegal file path" is usually thrown when wrong path is submitted to File constructor - not when using that file/directory. Your method works for me e.g when using quick test:

          var file:File = File.desktopDirectory;

          file.openWithDefaultApplication();     

          You could try also below solution that uses shell integration with Windows Explorer (Explorer.exe):

          var file:File = File.desktopDirectory;

          var path:String = file.nativePath;

          var processInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();

          var arguments:Vector.<String> = new <String>[path];

          processInfo.arguments = arguments;

          processInfo.executable = new File("c:\\Windows\\Explorer.exe");

          var process:NativeProcess = new NativeProcess();

          process.start(processInfo);

          (above version requires "desktopExtended" and native installer on deployment due to use NativeProcess)

          How to use Explorer.exe, e.g.:

          http://support.microsoft.com/kb/152457

           

          hth,

          kind regards,

          Peter

          1 person found this helpful
          • 2. Re: Open a Folder in Air 2.7
            BaronKarza Level 1

            Hi Peter,

            Thanks for you reply.

            Your example works because I think it's allowed to open the desktop directory

            Just try another one, on you hard disk c: for example and you'll see that "illegal file path"

            About the second solution, it's a nice one but I just wanted to stay more generic (however I think I will put an  "if you are on windows do this" ) and in the other case I will use a navigateToUrl...

            Thanks

            • 3. Re: Open a Folder in Air 2.7
              Peter Blazejewicz Level 4

              Hi,

              Just try another one, on you hard disk c: for example and you'll see that "illegal file path"

              I'm able to do that just following your snippet "as is":

              var file:File = new File("c:\\mydirectory\\mysubdirectory");

              file.openWithDefaultApplication();

              I could open "C:\mydirectory\mysubdirectory" (otherwise I would not answer with first post). Are you able to read that directory at all? (that is has your account enough privileges to read/write that directory?)

              regards,

              Peter

              • 4. Re: Open a Folder in Air 2.7
                BaronKarza Level 1

                Hi Peter,

                After some time I discovered that when I switched to Air2.7 I forgot to copy the airglobal.swf to his proper location under "Common/Configuration/ActionScript 3.0/AIR2.6/"

                I do not know if it was this that created the problem or simply that that day (the day I wrote my previous message) I had flash in "guru meditation"...

                However right now all works like it should.

                Thanks again