# How to put text file into ApplicationData.child folder?

**URL:** <https://forum.xojo.com/t/how-to-put-text-file-into-applicationdata-child-folder/23053>\
**Category:** macOS\
**Created:** [March 16, 2015, 7:56pm UTC](https://forum.xojo.com/t/how-to-put-text-file-into-applicationdata-child-folder/23053 "2015-03-16T19:56:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nic\_Kolbe](https://forum.xojo.com/user_avatar/forum.xojo.com/nic_kolbe/32/11644_2.png) [@Nic\_Kolbe](https://forum.xojo.com/u/Nic_Kolbe)\
**Post date:** [March 16, 2015, 7:56pm UTC](https://forum.xojo.com/t/how-to-put-text-file-into-applicationdata-child-folder/23053/1 "2015-03-16T19:56:41Z")

</div>

I am trying to put a folder “MyApp” and a text-file into it without success… Thanks for help! It works until MsgBox “Check 0”… Also, would the solution be different for iOS?

try  
dim f as FolderItem  
dim addPrefFolderItem as FolderItem  
dim dataStream as TextInputStream  
dim resultData as string  
dim addressePrefs as string  
f = SpecialFolder.ApplicationData.child(“MyApp”).child(“MyAppTextFile”)  
MsgBox “Check 0”  
addressePrefs = addPrefFolderItem.NativePath  
'read backup file  
MsgBox “Check 1”  
f = GetFolderItem(addressePrefs)  
if f.Exists then  
'File does exist  
dataStream = f.OpenAsTextFile  
resultData = dataStream.ReadAll()  
dataStream.Close  
if resultData = “” then  
'No data  
else  
'Some data  
end if  
else  
'File does not exist  
end if  
Catch error As RuntimeException  
'do nothing  
End Try

---

<div class="post-metadata">

**Author:** ![Kem\_Tekinay](https://forum.xojo.com/user_avatar/forum.xojo.com/kem_tekinay/32/154_2.png) [@Kem\_Tekinay](https://forum.xojo.com/u/Kem_Tekinay)\
**Post date:** [March 16, 2015, 8:00pm UTC](https://forum.xojo.com/t/how-to-put-text-file-into-applicationdata-child-folder/23053/2 "2015-03-16T20:00:38Z")

</div>

If the folder MyApp does not exist, you can’t get a child from it.

```auto
f = SpecialFolder.ApplicationData.Child( "MyApp" )
if not f.Exists then
  f.CreateAsFolder
end if
f = f.Child( "MyAppTextFile" )
```

---

<div class="post-metadata">

**Author:** ![Nic\_Kolbe](https://forum.xojo.com/user_avatar/forum.xojo.com/nic_kolbe/32/11644_2.png) [@Nic\_Kolbe](https://forum.xojo.com/u/Nic_Kolbe)\
**Post date:** [March 16, 2015, 8:13pm UTC](https://forum.xojo.com/t/how-to-put-text-file-into-applicationdata-child-folder/23053/3 "2015-03-16T20:13:58Z")

</div>

Thanks Kem, replaced the f=SpecialFolder… line with your code. Still it doesn’t make it past the next line

addressePrefs = addPrefFolderItem.NativePath

I basically copied and modified that “open file” code a while ago without proper understanding of the FolderItem story… It’s still a bit confusing…

try  
dim f as FolderItem  
dim addPrefFolderItem as FolderItem  
dim dataStream as TextInputStream  
dim resultData as string  
dim addressePrefs as string  
'f = SpecialFolder.ApplicationData.child(“MyApp”).child(“MyAppTextFile”)  
f = SpecialFolder.ApplicationData.Child( “MyApp” )  
if not f.Exists then  
f.CreateAsFolder  
end if  
f = f.Child( “MyAppTextFile” )  
MsgBox “Check 0”

```
addressePrefs = addPrefFolderItem.NativePath
'read backup file
MsgBox "Check 1"
f = GetFolderItem(addressePrefs)
if f.Exists then
  'File does exist
  dataStream = f.OpenAsTextFile
  resultData = dataStream.ReadAll()
  dataStream.Close
  if resultData = "" then
    'No data
  else
    'Some data
  end if
else
  'File does not exist
end if

```

Catch error As RuntimeException  
'do nothing  
End Try

---

<div class="post-metadata">

**Author:** ![Kem\_Tekinay](https://forum.xojo.com/user_avatar/forum.xojo.com/kem_tekinay/32/154_2.png) [@Kem\_Tekinay](https://forum.xojo.com/u/Kem_Tekinay)\
**Post date:** [March 16, 2015, 8:18pm UTC](https://forum.xojo.com/t/how-to-put-text-file-into-applicationdata-child-folder/23053/4 "2015-03-16T20:18:09Z")

</div>

At the point you use it, addPrefFolderItem is still nil.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:41pm UTC](https://forum.xojo.com/t/how-to-put-text-file-into-applicationdata-child-folder/23053/5 "2020-10-29T17:41:37Z")

</div>


