How to set temp path for this two methods?
System.IO.Path.GetTempFileName()
System.IO.Path.GetTempPath()
My company application was designed for Windows 2008 with .NET 4.0. However the application is going to support both Windows 2008 and Azure.
Since Azure does not allow local file writes, no temp file can be created in Azure. In the application, there are many places using temp file for massive works (that means we cannot put the data in memory since the temp file is huge.)
My plan is going to create a TempFileWrapper
to replace the original temp file generation. However, if there is simply way to change the return values from System.IO.Path.GetTempFileName()
and System.IO.Path.GetTempPath
, that saves my works.
Blatantly copied from this blog post, 3rd google hit:
var tempPath = RoleEnvironment.GetLocalResource("Temp").RootPath;
Environment.SetEnvironmentVariable("TEMP", tempPath);
Environment.SetEnvironmentVariable("TMP", tempPath);
The MSDN documentation describes how GetTempPath
finds the path:
TMP
environment variable.TEMP
environment variable.USERPROFILE
environment variable.So simply change the TMP
or TEMP
environment variable.
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