Click here to Skip to main content
15,993,109 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone, I'm using VB 2008 and I'm having problems.

I'm making a html editor and made everything like syntax, etc.
but I know how to save a file, but I don't know how to overwrite it. like'when you're editing a text file, you press ctrl+s and it automatically saves.
how to do that? thanks for helping in advance.

KrishGM
Posted

1 solution

Just write the file.
File.WriteAllText[^] just needs you to supply the path to the file, and the data to write (and there are other File.WriteXXX methods that do the same for different types of data) - provided you have a file name and path already, you don't need to ask again - just call the appropriate method and it's written.

It's a good idea to provide a backup facility though: write the file to a temporary file in the same folder, then rename the original, then rename the new file. That way, the user can "step back" if his updates caused a problem.
 
Share this answer
 
Comments
Member 11202273 8-Nov-14 6:54am    
How do I automatically provide the path?
OriginalGriff 8-Nov-14 7:15am    
If you follow the link, it does explain: the two parameters are the path, and the data to write.

So assuming you know where you want to store the file, you just pass itover as a string...and if you don;t know where to store it, then you need to get teh user to tell you, which means the SaveFileDialog! :laugh:
Think about it. When you create a new file in Word and press CTRL+S, you get a save dialog. The next time you press CTRL+S in the same file, you don't - because you told it the first time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900