Save as .txt Questions

I am using the code below to save a TextArea as a .txt file.
Is it possible to have the Window which opens up to be pre-defined with the OS X desktop as the default save location?

dim f as FolderItem = GetSaveFolderItem(FileTypes1.Text,"My Info") dim txt as TextOutputStream = textoutputstream.Create(f) txt.Write TextArea1.Text txt = Nil

I know I can also use the code below:

Dim dlg as New SaveAsDialog Dim f as FolderItem dlg.InitialDirectory=SpecialFolder.Desktop dlg.promptText="Prompt Text" dlg.SuggestedFileName="Suggested Filename" dlg.Title="Title Property" dlg.Filter=FileTypes1.Text f=dlg.ShowModal() If f <> Nil then Return True //file saved Else Return True //user canceled End if

  1. Which is the best way of achieving a default save location (snippet 1 or snippet 2)

  2. Are the 2 Return True statements in the second code snippet required, as I do not need anything special to happen if the file is saved, or the user cancels.

  3. Is it possible to allow the user to set an OS X tag on the file at the time of saving?

Thank you.

The second set of code you posted doesn’t actually save the file. All it does is request a file location/name from the user. You must then create the file and write the contents to it.

if f <> Nil then
   // code to save the file goes here
   dim txt as TextOutputStream = textoutputstream.Create(f)
   txt.Write TextArea1.Text
End If

Return True may or may not be required, depending on where this code is located. You didn’t mention that, so it’s impossible to answer the question.

Thanks Tim - I forgot to add the code which actually writes to the file :slight_smile:

Just realised that the tag option appears automatically when the save as wind is displayed :slight_smile:

Thank you.