Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing file in App_Data from a class in the App_Code folder

Tags:

asp.net

In ASP.Net there is the app_data folder which is not accessible to users via the web. I would like to store a file in this folder, and read from this file by using a class that I have in the App_Code folder.

Keep in mind that the current working directory here is going to be a directory such as "c:\","c:\windows\system32\", etc. and not the application directory. So something like "../App_Data/somefile" does not work.

There has to be something simple that I overlooked on how to access files in the App_Data folder programatically

How can I do this?

like image 683
Brian Avatar asked Mar 30 '09 14:03

Brian


1 Answers

You say you don't have access to context object but it's unclear why that would be.

If your code runs in response to a request then you can access the context as :-

HttpContext.Current

Failing that you can get to the root physical path for the application using:-

HttpRuntime.AppDomainAppPath
like image 102
AnthonyWJones Avatar answered Oct 14 '22 15:10

AnthonyWJones