25

I need to read a file there. I tried Assembly.ExecutingAssembly etc but that doesnt work.

1

4 Answers 4

27

From asp.net it's simple:

Server.MapPath("~/App_Data");//anywhere
Sign up to request clarification or add additional context in comments.

4 Comments

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/…
@CharlesBurns fixed, see at your question
I'm doing so in some cs class and the Server object was giving problems. HttpContext.Current.Server made it work.
@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
12

another way is:

AppDomain.CurrentDomain.GetData("DataDirectory");

1 Comment

This isn't documented on MSDN, so I would not recommend using this
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.

1 Comment

best answer so far. This one does the job. Thank you.
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");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.