Question

I need to use some folder for temp files. I tried to use

    string directoryPath = HttpContext.Current.Server.MapPath("~/tempFiles");

but when I publish it to IIS I had permission issues.

So I tried to use :

    string directoryPath = Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);

It works fine when I run my web application from VS2012, but I get an empty string when I publish it to iis and run it there.

I checked and loadUserProfile is "true".

Any other suggestion?

Was it helpful?

Solution

Some of the special paths are specific to the logged-in user, and special user accounts such as apppool may have no such folder. I'd suggest either using GetTempPath ( http://msdn.microsoft.com/en-us/library/system.io.path.gettemppath.aspx ) or creating a directory inside your website for such a purpose (but with security set so that website users can't browse to it).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top