From my C# code, that doesn't run from within IIS/ASP.NET, I need to add a user account permissions to the ASP.NET temp folder. (It is required while adding my site to IIS.) The folder on my local system is:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files
I'd hate to hard-code this path into my code, so I was wondering if I can retrieve it from .NET framework itself?
Path GetTempPath Returns the path of the current user's temporary folder.
Below is a typical folder structure for an ASP.NET web pages web site: The "Account" folder contains logon and security files. The "App_Data" folder contains databases and data files. The "Images" folder contains images. The "Scripts" folder contains browser scripts.
Hmm. I didn't know that it would be so complicated. For the lack of better answer, I was able to come up with something like this:
using System.Runtime.InteropServices; string net_base = Path.GetFullPath(Path.Combine(RuntimeEnvironment.GetRuntimeDirectory(), @"..\..")); string strTemp32 = string.Concat(net_base, @"\Framework\", RuntimeEnvironment.GetSystemVersion(), @"\Temporary ASP.NET Files"); string strTemp64 = string.Concat(net_base, @"\Framework64\", RuntimeEnvironment.GetSystemVersion(), @"\Temporary ASP.NET Files");
There're obviously two temp folders -- for 32-bit and 64-bit processes. It is based on this sample, and also relies on the assumption that default ASP.NET temporary folders are hard-coded
.
Correct me, if you find a better way?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With