I’m creating a SQL CE database file programmatically and want to make sure I’m creating a fresh new one each time so I added the delete method. Since each database file is created in DataDirectory, I would want to delete the file in DataDirectory as well, but it’s giving me
“illegal characters in path” error
following is my code:
/* illegal characters in path */
File.Delete("|DataDirectory|\\Foo2Database.sdf");
string connString = @"Data Source=|DataDirectory|\Foo2Database.sdf";
SqlCeEngine engine = new SqlCeEngine(connString);
engine.CreateDatabase();
|DataDirectory|is connection string notation and is not related to file system pathes.You can delete the file using the code like this:
You can get current
DataDirectoryviaAppDomain.CurrentDomain.GetData("DataDirectory");if you set it.If you have asp.net
DataDirectorywill beServer.MapPath("~/App_Data");by default.