I have a Visual C# 2008 project. Within my project explorer, I have an SQL CE database (sdf file) so I can work with the database and dataset in the designer. At runtime, the sdf file is copied to the output directory. When the user saves their own database, this sdf file is copied to whatever filename the user chooses and their dataset is saved to the copy. No problem so far.
I’d like to do this a different way if possible. Rather than having the sdf file copied out when the program first runs, I’d like to set it up so that when the user saves their database, THEN it copies out the sdf file using the name of their choosing and saves their dataset to it.
I have read ways to write out the file as binary, which does work but it takes several lines of code that just seems unnecessary. Isn’t there a way just to tell the program “hey, go ahead and copy this sdf file out real quick”? After all, the program is able to automatically do it when you first run it.
Add the database file as a resource in your project. Then when you want the file to be appear just write out the byte array to a file.
Example: