Getting current directory in .NET web application

.net, asp.net, c#, directory, filepath

Solution

The current directory is a system-level feature; it returns the directory that the server was launched from. It has nothing to do with the website.

You want `HttpRuntime.AppDomainAppPath`.

If you're in an HTTP request, you can also call `Server.MapPath("~/Whatever")`.

Problem

So I have a web project, and I'm trying to get the root directory of the website using the c# method `Directory.GetCurrentDirectory()`. I don't want to be using a static path as the file locations will be changing in the future. This method is running in my imageProcess.aspx.cs file, but where I thought it would return: ``` C:\Users\tcbl\documents\visual studio 2010\Projects\ModelMonitoring\ModelMonitoring\imageProcess.aspx.cs ``` I'm instead getting: ``` C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\ ``` Can anyone explain why this is happening and what a possible solution might be? Thanks a lot.

Original source

Related problems