Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to create a button that uses SystemDialogInput["FileOpen"] to browse for a file and assigns the file name to a variable.

For example:

 {Button["Select the file", fname = SystemDialogInput["FileOpen"]], Dynamic[fname]}

This works most of the time; however, when the file that I browse to is several nested folders away from the default directory, it does not update the value of fname.

Is there some way around this? Or is there a better function to use? I eventually would like to use this button within Manipulate.

share|improve this question
Try adding the option Method->"Queued" to your Button. – kglr Feb 22 '13 at 4:23

The Method -> "Queued" option is important.

I also suggest to use current or data file directory as a starting point.

Also do not forget to check file if it is "$Canceled" (in the event of cancellation).

Here is an example just copied from one of my programs:

Button["Load", file = SystemDialogInput["FileOpen", {NotebookDirectory[] <> "data\\",
      {"Data files" -> {"*.txt"}}}];
      If[ file != "$Canceled", data = Get[file]; ], Method -> "Queued"]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.