Well then you simply need to store where the document is located when you open it and then refer to that location when you save it. You could do this by having either a class level or global variable (depends on the design of your code) that just stores this and is updated whenever the user opens a new document.