UnauthorizedAccessException on Path.GetTempFileName Call

bdam

Member
Joined
Jan 13, 2010
Messages
6
Programming Experience
5-10
So I can't seem to figure this out. I am updating a project of mine to Visual Studio 2012 and targeting .NET 4.0. I am running this on a 64-bit Windows 7 machine using a regular user. When I call Path.GetTempFileName I am getting an Unauthorized Access Exception. To be clear; I'm not even trying to read or write yet ... the call itself if raising this exception. Other calls in the program the are trying to access the AppData folder throw the same thing despite checking that the user running the app is indeed my user and that my user does have access to those folders.

I'm just sort of perplexed here ... I can't see any reason not to have full access to these folders. For reference, the full paths I am referring to are D:\Users\Bryan\AppData\Roaming and D:\Users\Bryan\AppData\Local\Temp. If you want to see the code yourself you can browse it here:
http://sourceforge.net - SaveSettingsToFile(settings As Settings)
http://sourceforge.net LoadCert()

Any ideas? The only though I have is that I am running my users folder on a secondary hard drive (D:) rather than (C:). However the environment variables and the paths mentioned in the area are correct.
 

Attachments

  • AppData Error.png
    AppData Error.png
    18.8 KB · Views: 35
  • GetTempFileName Error.png
    GetTempFileName Error.png
    14.8 KB · Views: 32
I don't know why you're getting those exceptions and it does seem strange. The one thing I can tell you is that Path.GetTempFileName actually does create the file it returns the path of, so you are actually writing to the folder so, if you don't have access, the exception is justified. It's just that you really ought to have access and I have no explanation for it not being so.
 
Thanks for the quick reply; if nothing else it's always nice to know I'm not crazy and/or incredibly stupid.
 
Back
Top