Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 8 down vote accepted

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:

SystemDialogInput["FileSave", 
                  {
                    FileNameJoin[{NotebookDirectory[],"*.*"}], 
                    {
                      "JPEG" -> {"*.jpg", "*.jpeg"}, 
                      "Portable Network Graphics" -> {"*.PNG"}
                    }
                  }
]
share|improve this answer
    
Thank you. I found that Save[SystemDialogInput["FileSave"],data] allows me to save data to a file. –  Christina Jun 7 '12 at 21:12
    
@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. –  Sjoerd C. de Vries Jun 7 '12 at 21:29
    
Thank you for all the help. It works perfectly now. –  Christina Jun 11 '12 at 13:41

Your Answer

 
discard

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.