3

Using VS2008, c#.

When I call Path.GetTempFileName(), the temp file generated is something like: C:\Users\allensamuel\AppData\Local\Temp\tmpC1D0.tmp

However, in the company I work, using the C: drive for files is not prohibited. Rather, a login scrips points the user's "my documents" and "home" area (decouemtn and settings etc) are pointed to a networked "H:" drive.

I can't see why Path.GetTempFileName() is choosing the C: drive, or how to instruct it to use the H drive.

Any ideas? I don't really want to create my own version ofthe above method.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
Iain
  • 105
  • 2
  • 8
  • You might find this handy... http://msdn.microsoft.com/en-us/library/system.io.path.gettemppath.aspx – Austin Salonen Mar 01 '11 at 20:31
  • Thank you - I am not yet on .Net 4, strange how they now put the environment variables in the remarks section for this version but not 3.5! – Iain Mar 02 '11 at 13:51

1 Answers1

5

It chooses this path because it is set in %TEMP% environment variable. Try setting this variable to point somewhere around H drive.

Snowbear
  • 16,924
  • 3
  • 43
  • 67
  • +1 One would think that this would be set with some domain policy. – Austin Salonen Mar 01 '11 at 20:30
  • And when H: is networked (which OP claims it is) fileIOPermissions? – rene Mar 01 '11 at 20:33
  • @rene, I believe it makes no difference whether it is network drive or not. If user has write permissions it should work fine, otherwise why OP would want that? – Snowbear Mar 01 '11 at 20:36
  • I was more referring to CodeAccessSecurity. Is H:\ considered a local drive and only unc paths like \\server\share are Network? OP is on 2.0 so the relaxed rules are not yet in place? – rene Mar 01 '11 at 20:40
  • Thank you for this, I can confirm that %TEMP% is set to the C drive, and the .Net 4 documentation explicityly says that this env variable controls the behaviour of this method (thanks also to Ausin above). I will check why this has happened because I can't think that our domain policy should be leaving this as the C drive. – Iain Mar 02 '11 at 13:54