3

I am developing an application using Adobe AIR.

How can we get absolute path of file or "nativePath" of file (as we call it in Flex/AIR) when we use FileReference to browse a file ?

I know there are security concerns related to this but is there any hack or is there a direct solution that I am unaware of?

Please help me out.

Thanks.

Prashant
  • 5,331
  • 10
  • 44
  • 59

2 Answers2

10

Since File extends FileReference, you can do this:

var file:File = new File();
file.addEventListener(Event.SELECT, onSelect);
file.browse();


private function onSelect(e:Event):void
{
   trace(e.target.nativePath);
}
J_A_X
  • 12,857
  • 1
  • 25
  • 31
  • +1 I actually looked at the docs for both of those classes; but didn't catch that. – JeffryHouser Apr 26 '11 at 21:01
  • Thanks a lot J_A_X for a detailed answer, this is exactly what I was looking for.....may God bless you... – Prashant Apr 27 '11 at 04:49
  • J_A_X can I select multiple files in browse dialog box, as in FileReferenceList, using File object solution that you suggested ? – Prashant Apr 27 '11 at 18:37
  • If you want to select more than one file, use the `FileReferenceList` class. I really suggest you [look up the API](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/index.html#top). – J_A_X Apr 27 '11 at 18:48
  • 1
    I had started with FileReferenceList but then I found the limitation of not getting the full path or native path of file with that. Anyways, thanks for prompt responses...May Buddha bless you :) – Prashant Apr 27 '11 at 19:03
  • 1
    Actually, my bad, you can do it in the `File` class with [browseForOpenMultiple](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html#browseForOpenMultiple()). The example even does exactly what you want. – J_A_X Apr 27 '11 at 19:19
  • J_A_X....Hats off to you man....Now THAT is exactly what I want...You are The Savior...thanks a ton....now I feel like grilling the API more to find out solutions :).....Thanks again.. – Prashant Apr 27 '11 at 19:59
0

This way the last used folder will be opened and you have a filename in your dialog (if you need that):

//Save dialog:
var oFile:File = new File();
oFile.save(aData, 'MyData.txt');
oFile.addEventListener(Event.COMPLETE, onComplete);

function onComplete(e:Event):void{
    trace(e.target.nativePath);
}
Ilyssis
  • 4,849
  • 7
  • 24
  • 30