Tuesday, January 15, 2013

What is DataDirectory in Asp.net?

In Asp.net, DataDirectory (which is enclosed in a pipe symbol in a connection string) is a replacement string which indicate path to your database file and also eliminate the need to hard-code the full path to your database file as .

By default DataDirectory refers to  App_Data folder under the root of your web application.For Desktop application, DataDirectory points to bin directory.So,now the question is what is we wanted DataDirectory to point to a different location(other than App_Code folder)?

The issue can be resolved using AppDomain.And the following line will set DataDirectory path before using it in connection string.

AppDomain.CurrentDomain.setData("DataDirectory",@"c:\Data\");

That would make your DataDirectory to point to "c:\Data\database.mdf path.






No comments:

Post a Comment