Save to same directory?

Hi,
When I click on my Load text file button, I have the following code which allows the user to determine which .txt file gets opened:

[code]Dim f As FolderItem = GetOpenFolderItem(FileTypes1.Text)
If f <> Nil Then
If f.Exists Then
Dim t As TextInputStream
t = TextInputStream.Open(f)
t.Encoding = Encodings.UTF8
NotesField.Text = t.ReadAll
t.Close

// SET THE SavePath PROPERTY TO THE PATH DICTATED BY f
SavePath = f[/code]

However, when I try to save a .txt file to the same directory as where it was opened from (via the code below) - I simply get another prompt, asking where to save to?

Any ideas why my code below does not cause the .txt file to simply get saved to where it came from?

Dim f As FolderItem = SavePath Dim tos As TextOutputStream tos = TextOutputStream.Create(f) tos.Write(NotesField.text) tos.Close

Thanks.

The second set of code doesn’t cause the prompt.
Thats coming from GetOpenFolderItem

You must be calling the whole code again.

To save a file in the same location as the original, you need to use
SavePath.parent.child(“My new file.txt”)

(and this assumes that SavePath is actually a folder item object, not a string.)

If you want to write back to the same file, then

Dim tos As TextOutputStream tos = TextOutputStream.Create(SavePath) tos.Write(NotesField.text) tos.Close

should do it

Thanks Jeff - that worked :slight_smile: