PDA

View Full Version : Path to Access database in codefiles


tinker
04-15-2009, 08:12 AM
I need to read (read-only) an Access database where the name of database will change depending on the current date. On my workstation, I set the connection string in the code file like:

string strFilePath = "E:\\databases\\" + DateTime.Now.ToString("MMyy") + ".mdb";

And use it first as:

FileInfo objTestFile = new FileInfo(strFilePath);
litUpdated.Text = string.Format("{0:h:mm tt on MMMM d, yyyy}", objTestFile.LastWriteTime);


I've been playing with this all day to use the "_database" folder, and cannot seem to get it right.

Help, please?

(I'm not locked in to doing this is the code file, but if there's a way to combine a <connenctionString> with a variable file name, I haven't found it..)

- Tinker

bruce
04-15-2009, 11:36 AM
use server.mappath function.

eg.

string strFilePath = server.MapPath("_database") + DateTime.Now.ToString("MMyy") + ".mdb";