NsIFilePicker: Difference between revisions

From MozillaZine Knowledge Base
Jump to navigationJump to search
(moved to MDC)
Line 1: Line 1:
{{extdev}}
Moved to http://developer.mozilla.org/en/docs/nsIFilePicker
{{wrongtitle|title=nsIFilePicker}}
 
The filepicker component is used to display standard "Open File"/"Save File"/"Select Folder" dialogs.
 
== Example ==
Here's an example:
<pre>
const nsIFilePicker = Components.interfaces.nsIFilePicker;
 
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker);
fp.init(window, "Dialog Title", nsIFilePicker.modeOpen);
fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
 
var rv = fp.show();
if (rv == nsIFilePicker.returnOK)
{
  var file = fp.file;
  // work with returned nsILocalFile...
}
</pre>
 
If your code is a component and <code>window</code> is not defined, you can get one using [[nsIWindowMediator]].
 
== Notes ==
* If you pass empty string as dialog title, the dialog will have default title
* When checking return value for Save dialog, be sure to check for nsIFilePicker.returnReplace too.
* Available modes: modeOpen, modeSave, modeGetFolder, modeOpenMultiple.
* Available filters: filterAll, filterHTML, filterText, filterImages, filterXML, filterXUL, filterApps.
* To start with a specific filter, use the filterIndex property
* Set the property displayDirectory to a nsiLocalFile to default to a given directory
----
{{msg:stub}}
 
== References ==
*[http://xulplanet.com/references/xpcomref/ifaces/nsIFilePicker.html nsIFilePicker interface].
 
[[Category:Example code|nsIFilePicker]] [[Category:XPCOM example code|nsIFilePicker]] [[Category:JavaScript example code|nsIFilePicker]]

Revision as of 18:44, 17 June 2006