Appcelerator Titanium enables you to show a dialog box to select files which you would like to save or open. mybloggingplanet.com/2015/05/high-pr-do-follow-social-bookmarking-sites.html?showcommentx3d1434098968647

To open a SaveAs dialog box, we first set up the options object, and then call the function to open the dialog, passing it the callback function to call once it is closed.

  var options = {
     title: "Save file as...",
     types: ['*'],
     typesDescription: "All files",
     path: Titanium.Filesystem.getUserDirectory()
  }

  Titanium.UI.openSaveAsDialog(callbackFunc, options);

In types we put the file types filter, for example ['doc', 'txt]. The path is the default path to point the dialog to.

Next in the callback function, we can reference the filename which is returned as an array, which when saving a file is always going to be one element, but may be multiple filenames for an Open dialog.

   callbackFunc = function(filenames){
      var fileSelected = filenames[0];
   }

Creating a file chooser dialog is very similar. This dialog allows multiple files to be selected.

   var options = {
      multiple: true,
      title: "Select files to open...",
      types: ['doc', 'txt'],
      typesDescription: "Documents",
      path: Titanium.Filesystem.getUserDirectory()
   }
   Titanium.UI.openFileChooserDialog(callbackFunc, options);

In the callback function, the only difference is that the array of filenames may have more than 1 filenames in it.

   callbackFunc = function(filenames) {
      var firstFileSelected = filenames[0];
      var secondFileSelected = filenames[1];
   }

That is all there is to showing and processing file dialogs.

I would point you to the Titanium API documention at this point, but have found no reference to the dialogs in the 0.4 documentation.

Share