Change .NET change path

How to set a temporary path for these two methods?

System.IO.Path.GetTempFileName() System.IO.Path.GetTempPath() 

My company’s application was developed for Windows 2008 with .NET 4.0. However, the application will support both Windows 2008 and Azure.

Because Azure does not allow writing to a local file, it is not possible to create a temporary file in Azure. There are many places in the application where the temporary file is used for large jobs (this means that we cannot put data into memory because the temporary file is huge).

My plan is to create a TempFileWrapper to replace the original generation of temporary files. However, if there is simply a way to change the return values ​​from System.IO.Path.GetTempFileName() and System.IO.Path.GetTempPath , this will save my work.

+4
source share
2 answers

Blissfully copied from this blog post , google 3rd hit:

 var tempPath = RoleEnvironment.GetLocalResource("Temp").RootPath; Environment.SetEnvironmentVariable("TEMP", tempPath); Environment.SetEnvironmentVariable("TMP", tempPath); 
+7
source

The MSDN documentation describes how GetTempPath finds the path:

  1. The path specified in the TMP environment variable.
  2. The path specified in the TEMP environment variable.
  3. The path specified in the USERPROFILE environment variable.
  4. Windows directory.

Therefore, just change the TMP or TEMP environment variable.

+5
source

Source: https://habr.com/ru/post/1332700/


All Articles