I need to read a file there. I tried Assembly.ExecutingAssembly etc but that doesnt work.
4 Answers
From asp.net it's simple:
Server.MapPath("~/App_Data");//anywhere
4 Comments
Charles Burns
Except sometimes it's not. Deployed websites often have their App_Data in
~/bin/App_Data, but use ~/App_Data locally. Using the |DataDirectory| substitution is broken in these cases. See stackoverflow.com/questions/18706945/…Roland Kwee
@CharlesBurns fixed, see at your question
Vasily Hall
I'm doing so in some cs class and the Server object was giving problems. HttpContext.Current.Server made it work.
Alberto León
@ozn is not common these days to use App_Data, except azure is using it to put Webjobs. Another question is the App_Data could be in bin directory as CharlesBurns metioned
another way is:
AppDomain.CurrentDomain.GetData("DataDirectory");
1 Comment
Hoppe
This isn't documented on MSDN, so I would not recommend using this
String base = AppDomain.CurrentDomain.BaseDirectory;
//Using above code , you will get base directory of your applications.
String pathToData_App = base + "/App_Data/SqLite.db";
Above code works for me.
1 Comment
Paras Parmar
best answer so far. This one does the job. Thank you.