Alex Rivera | Logout

Accessing file in App_Data from a class in the App_Code folder

Asked 2009-03-30T14:01:35.270
12

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?

Edit
Report

1 Answer

8

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
answered 2009-03-30T14:07:19.063

Your Answer