Actually, on reflection, a much more elegant solution might be to include a
blank Access database as an Embedded Resource in your app, as it will be a
mere 64k in length. Then, when you need to create a new DB, just write it
out to the file system wherever you need it, naming it as required.
1) Using Access, create a blank database called something like template.mdb
(or whatever).
2) Create a new C# WinForms project called Brian (or whatever).
3) Drag the newly created DB into your C# project, setting its Build Action
property to Embedded Resource.
4) Use the following code to extract the blank DB out of your assembly and
onto the hard drive:
try
{
byte[] abytResource;
System.Reflection.Assembly objAssembly =
System.Reflection.Assembly.GetExecutingAssembly();
objStream = objAssembly.GetManifestResourceStream("Brian.template.mdb");
abytResource = new Byte[objStream.Length];
objStream.Read(abytResource, 0, (int)objStream.Length);
objFileStream = new FileStream(<path> + "\\" + <newName.mdb>,
FileMode.Create);
objFileStream.Write(abytResource, 0, (int)objStream.Length);
objFileStream.Close();
}
catch (Exception)
{
throw;
}
finally
{
if (objFileStream != null)
{
objFileStream.Close();
objFileStream = null;
}
if (objStream != null)
{
objStream = null;
}
}