Question

I'm creating a richtextbox editor and need to put a save function as well as a save as. I can easily do a save as function by using the savefiledialog but im not sure how to save without this. Can anyone help?

Was it helpful?

Solution

Create a field somewhere, say string filename. Set it to null initially.

When a document is opened, store the file name in a filename.

When a document is saved through Save As, also store this file name in filename.

When Save is invoked, check the value of filename. If it is null, invoke Save As instead. If it is not null, save to the file name specified in filename.

OTHER TIPS

The way this usually works is to keep track of the file name the user either opened or saved as.

Then, when they use the Save function, simply save to the file name that was previously specified. If no file has been specified, then show the Save As.

Isn't "Save" simply the following (in pseudocode)?

Save() = 
    WriteTo(oldfilename)

SaveAs() = 
    stream = OpenDialog()
    oldfilename = stream.filename
    Save()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top