I need to read a file there. I tried Assembly.ExecutingAssembly etc but that doesnt work.
Asked
Active
Viewed 4.1k times
4 Answers
27
From asp.net it's simple:
Server.MapPath("~/App_Data");//anywhere
realMarkusSchmidt
- 4,244
- 1
- 28
- 33
Alberto León
- 2,729
- 2
- 24
- 24
-
2Except 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 http://stackoverflow.com/questions/18706945/datadirectory-returns-wrong-path-to-appdata-folder – Charles Burns Sep 16 '13 at 04:08
-
-
I'm doing so in some cs class and the Server object was giving problems. HttpContext.Current.Server made it work. – Vasily Hall Apr 26 '17 at 20:25
-
@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 – Alberto León May 28 '19 at 09:24
4
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.
Rakesh Chaudhari
- 2,962
- 1
- 24
- 23
3
I needed to execute ELMAH scripts for AppData so is used this
var elmahScript = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ELMAH-1.2-db-SQLServer.sql");
Ali Umair
- 1,356
- 21
- 38