Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get path of App_Data folder in the Seed method of EF migration configuration class

How do you get the path of the App_Data folder in the Seed method of the configuration class of code first migrations.

I want to read from a file I've put in the App_Data folder and the Seed method runs after the update-database command. HttpContext.Current.Server.MapPath obviously does not work because there is no HttpContext at that point.

like image 430
NVM Avatar asked Feb 15 '13 18:02

NVM


2 Answers

I got it to work with something like: string MyPath = AppDomain.CurrentDomain.BaseDirectory + "/../App_Data"

because AppDomain.CurrentDomain.BaseDirectory ends at the "/bin" directory.

like image 80
user1598521 Avatar answered Oct 13 '22 10:10

user1598521


Here is a quick-and-dirty way to get you started:

var myPath = AppDomain.CurrentDomain.BaseDirectory;
//to quickly show the path, either attach another debugger or just throw an exception
throw new Exception(myPath);
like image 34
Rusty Divine Avatar answered Oct 13 '22 09:10

Rusty Divine