Save to the same location?

Hi,
I have a load .txt button which opens a .txt file into a textarea, and the displays it’s file name in a Listbox row.
The file path is saved in a property “filepath” (type FolderItem).

If I then open a second .txt file, the filepath property obviously changes to the path of this second .txt file.
All ok so far.

The problem is, that when changes are made and it comes to saving back to the same path the .txt file came from - it cannot be saved to filepath, because that is still set to the path of whatever .txt file was opened last.

Any ideas as to how I overcome this?

Remember the first file path as well (string variable).

Detlef - I don’t quite understand?
Could you elaborate?

Thanks.

Well, it looks like you need to store a FolderItem for each text file opened, and not just for the most recent file as you do now. The Listbox would be a good place since you create a new row for each file anyway.

This is the code I have, so far for loading .txt files:

[code]// ADD LISTBOX ROW
FilesListbox.AddRow(f.name)

// SET THE FILE’S TEXT CONTENT TO THE ROWTAG
FilesListbox.RowTag(FilesListbox.LastIndex) = tis.ReadAll
// SET THE FILEPATH TO THE CELLTAG
FilesListbox.CellTag(FilesListbox.LastIndex, 0) = f
FilesListbox.ListIndex = FilesListbox.LastIndex[/code]

And here is the line of code for saving a .txt file back to it’s original path:

tos = TextOutputStream.Create(FilesListbox.CellTag(FilesListbox.ListIndex, 0))

The problem now, is that it saves to the file path of the newly selected listbox item, and not to the path for the current item?

I feel I am almost there - but not quite :slight_smile:

It looks like you are using the wrong row index – FilesListbox.ListIndex would be the index of the last row added while you must use the index of the currently selected row.

:frowning: Now I am totally confused - I have no idea which line of code is wrong?

What are you doing to save the file, pushing a button? Or what?

Just forget what I wrote; it was nonsense. Actually your code looks to be correct. Maybe there is something else at work here in other parts of vour code.

Thanks guys - It is ok, I am now totally rewriting the code :slight_smile: