Saving a file not in the app folder

  1. 4 days ago

    Armando S

    Mar 24 Parma, Italy

    Hello,
    I managed to save the results of a calculation in the same folder as the app itself using f = New FolderItem("MyFile", FolderItem.PathModes.Native).
    I'm unable to save it somewhere else, though. In fact, I do not understand how to specify the where and what using a dialog (SaveFileDialog?).
    I'd appreciate if anybody can give me an example on how to do it

    Here is my new version: https://www.dropbox.com/s/d7r4gmzfz29q7qv/DataPasqua.zip?dl=0 . I made f a property of the window. That way you can load and save one file. The dialogs are only shown if f = nil. I've also corrected the TextAreas so that they load the new valued.

  2. Jeff T

    Mar 24 Pre-Release Testers Midlands of England, Europe

    Amazed you were allowed to do that.
    Try this: (API1 syntax)

    Dim dlg as New SaveAsDialog
    dlg.InitialDirectory=specialfolder.documents
    dlg.promptText="Save a file"
      dlg.SuggestedFileName="Myfile.txt"
    f=dlg.ShowModal
  3. Norman P

    Mar 24 Pre-Release Testers, Xojo Pro outside drowning sorrows

    http://docs.xojo.com/SaveFileDialog
    the issue is that the comments at the end are wrong
    the dialog does not actually SAVE anything - it either gives you a NIL (do not save this) or a place the user selected TO save the file to so you just use the returned folderitem instead of creating one

    Var dlg As New SaveFileDialog
    Var f As FolderItem
    dlg.InitialFolder = SpecialFolder.Documents
    dlg.PromptText = "Prompt Text"
    dlg.SuggestedFileName = "Suggested Filename"
    dlg.Title = "Title Property"
    dlg.Filter = FileTypes1.Text // defined as a file type in FileTypes1 file type set
    f = dlg.ShowModal
    If f <> Nil Then
      // this is where the file should be saved
    Else
      // user canceled so do nothing
    End If
  4. 3 days ago

    Armando S

    Mar 25 Parma, Italy

    So the FolderItem f will be placed placed inside whatever folder was selected by the modal dialog, assuming f is not NIL. The code to save whatever data needs to be stored should work to place everything inside f, and that should be the trick. Am I correct?

  5. Beatrix W

    Mar 25 Pre-Release Testers, Third Party Store Europe (Germany)

    Yup. You make a folderitem. Then you get a binarystream and let that write to the folderitem.

  6. Armando S

    Mar 25 Parma, Italy

    It's still very hazy. As I said, I managed to save and retrieve it if everything goes in the same folder as the app itslef. Choosing a different location is a differen matte altogether.
    I attach a link to the application. It is a simple application which determines the date of Easter based on the year. Nothing serious but this virus keeps everybody at home so I have more time to play with Xojo:

    https://www.dropbox.com/s/zjbj77w861fvukk/Data%20Pasqua%20save%201.2.xojo_binary_project?dl=0

    Thank you

  7. Beatrix W

    Mar 25 Pre-Release Testers, Third Party Store Answer Europe (Germany)

    Here is my new version: https://www.dropbox.com/s/d7r4gmzfz29q7qv/DataPasqua.zip?dl=0 . I made f a property of the window. That way you can load and save one file. The dialogs are only shown if f = nil. I've also corrected the TextAreas so that they load the new valued.

  8. Armando S

    Mar 25 Parma, Italy

    I'm sorry Beatrix, clicking on the link you provided I only get a blank DropBox page with DataPasqua.zip written on top but not clickable, so I cannot download the file.
    Could you check the link again or send it some other way?

    Thank you

  9. Emile S

    Mar 25 Europe (France, Strasbourg)

    Armando:

    The applications are meant to resides in the Applications folder.

    On macOS, when you save a file into the Applications folder, then decide to move it elsewhere, you will copy a link to that file (you will not move the file).

    Also, using a BinaryStream to save text data is not what most of people will do (and if some will do that, they will have a very good reason).

    As far as I understand, these are numeric values, save them as is (and read them accordingly, because you will read them at a moment or another).
    You do not know how to transform a text data into a numeric data ? Look at the documentation (http://docs.xojo.com/Val and read the See Also paragraph).

    At last, you can save the data in a file silently: avoid the dialog display as it is said earlier (above).

    The world current situation is stressing, so I can understand you.

    In the future, before asking questions here (or waste time searching how to in Xojo), lookhow things are done in the OS (in the above case, TextEdit in macOS, WordPad in Windows): where they want to store the data by default for this example.

    These are advices, clues, nothing else.

  10. Emile S

    Mar 25 Europe (France, Strasbourg)
    Edited 3 days ago

    @Armando S Could you check the link again or send it some other way?

    Use this one:

    https://www.dropbox.com/s/d7r4gmzfz29q7qv/DataPasqua.zip?dl=1

    Note the ending 1 (instead of 0): it says to the web target to download directly the file instead of displaying a download page interface. Sometimes I too forgot the change (in fact I forgot too).

  11. Beatrix W

    Mar 25 Pre-Release Testers, Third Party Store Europe (Germany)

    Tomorrow.

  12. Armando S

    Mar 25 Parma, Italy

    Disregard, thank you. It was probably a glitch in my web services provider but it worked, eventually. I tried your solution and it works very well for me.

    Thanks a lot for your help

or Sign Up to reply!