Saving a file to a folder in Application Data?

  1. 3 months ago
    Edited 3 months ago

    I am trying to create a folder in Application Data and place a file called TextFile in there. I keep getting I/O exception errors with this. Can anyone lend a hand?

    dim appFolder as folderitem
    
    appFolder = SpecialFolder.ApplicationData.Child("AppFolder").Child("TextFile")
    appFolder.CreateAsFolder
    
    dim numStream as TextOutputStream
    
    if appFolder <> nil then
      
      numStream = TextOutputStream.Create(appFolder)
      if numStream <> nil then
        numStream numbert.text
    numStream.close
      end if
    end if
    
    appFolder = SpecialFolder.ApplicationData.Child("AppFolder")
    appFolder.CreateAsFolder
    Dim AppFile as Folderitem = AppFolder.Child("TextFile")
  2. Sam R

    Jul 5 Pre-Release Testers, Xojo Pro, Third Party Store Hengchun, Pingtung, Taiwan

    @Matthew J appFolder = SpecialFolder.ApplicationData.Child("AppFolder").Child("TextFile")

    Your specifying the AppFolder and the TextFile on the same line, then trying to create a text file where you've just created a folder.

  3. Emile S

    Jul 5 Europe (France, Strasbourg)

    @Matthew J appFolder = SpecialFolder.ApplicationData.Child("AppFolder").Child("TextFile")

    Worst:
    I just fall into an error in a project where the construction was the same:
    one (all) Childs does not exists…
    (none of the passed Child folders exists in my Boot SSD.)

  4. Greg O

    Jul 5 Xojo Inc Answer
    appFolder = SpecialFolder.ApplicationData.Child("AppFolder")
    appFolder.CreateAsFolder
    Dim AppFile as Folderitem = AppFolder.Child("TextFile")
  5. Greg O

    Jul 5 Xojo Inc

    You should also check LastErrorCode from CreateAsFolder or at least check if it exists afterwards. Just in case that fails.

or Sign Up to reply!