Q: VB.NET: Check if file is saved? I'am creating a script editor for my own purposes.
And i have a menu option called "Close", and i want to check if the file is saved or not, so it no code get lost by clicking wrong.
Anyone have a idea how i check if the file is saved?
-Stian

A: Check if the file exists, using the shared File.Exists method:
File.Exists(filePath)


Update:
If you want to see if the save of an existing file was successful, you can use the FileInfo class - it has a LastWriteTime method that you can call before and after the save and compare the results of.

A: Have a boolean value (NeedsSaved) that is set to true then the text changes in your textbox. Set the value to false when save is invoked. If closing and NeedsSaved is true, then ask if they want to save. That's a down and dirty method, but would probably work well.

A: SpectralGhost's solution is the usual one. You would n't normally want to attach the saved state of your data to the operating system file. Waht if you wanted to post it to web service or stick it in a database for instance...
Only other option I can see would be to query the OS to for the state of the file, for that to work you'd want to open it exclusive when planning to write, check to see if you can close the readonly file, open write exclusive, deal with created or not. Check whether the OS has finished writing to the file, Write your Disk IO basiacally...
A lot of work compared to sticking one boolean somewhere and setting / resetting at the relevant points of the code...
