I would like to export data to a file using a SaveAs type dialog, using something like FileNameSetter[name,"Save"] to give a browse button.

Any help with this would be greatly appreciated. It is very possible that I have simply misunderstood the documentation.

Many thanks, Christina


1 Answer 1


SystemDialogInput["FileSave"] will do this for you.

Something like

fileName = SystemDialogInput["FileSave"]
If[fileName != $Canceled, Export[fileName, myData]]

should do the whole trick. The fire extension determines the type of export (if MMA knows it and supports it).

Preselecting a directory path and filtering allowable file extensions can be done as follows:

                      "JPEG" -> {"*.jpg", "*.jpeg"}, 
                      "Portable Network Graphics" -> {"*.PNG"}
  • $\begingroup$ Thank you. I found that Save[SystemDialogInput["FileSave"],data] allows me to save data to a file. $\endgroup$
    – Christina
    Jun 7, 2012 at 21:12
  • $\begingroup$ @Christina Save is fine if you just want to save some Mathematica symbols to be read in again by Mathematica. If you want to save data in a more structured and exchangeable format Export is usually the first choice. $\endgroup$ Jun 7, 2012 at 21:29
  • $\begingroup$ Thank you for all the help. It works perfectly now. $\endgroup$
    – Christina
    Jun 11, 2012 at 13:41
  • $\begingroup$ Thank you for this answer. It has helped me a lot. I found that I needed to change "If[fileName != $Canceled, Export[fileName, myData]]" to "If[UnsameQ[fileName, $Canceled], Export[fileName, myData]]" otherwise in case the user rejected the file name I suggested and entered another valid filename, Mma was unable to evaluate the 'If" condition. $\endgroup$
    – Simon
    Nov 10, 2017 at 21:42
  • 1
    $\begingroup$ @Simon Glad to be of help. UnsameQ (=!=) is indeed the better choice in many inequalities. $\endgroup$ Nov 11, 2017 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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