Krishna Krishna - 3 months ago 12
ASP.NET (C#) Question

Get Temp ASP.NET folder for application

I'm trying to get a specific application base ASP.NET Temp folder. I know we can use

HttpRuntime.CodegenDir
property to get the actual temp asp folder that the application is writing to. Is there any way I can get location to the base folder for that application in C#? Example:

<server>\c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\<AppName>

Answer

For any other who stumble on this question,

I couldnt find any direct way to get it. the way i resolved this is to get executing assembly location using below line

Assembly.GetExecutingAssembly().Location;

And then get to the parent folder which is the application name recursively using

var dir = new DirectoryInfo(path);

        while (dir.Parent.Name != folderName)
        {
            dir = dir.Parent;
        }
        return dir.Parent.FullName;

which will give me the required path im looking for.