c# Access to path denied? -


I'm having trouble with an error I searched the web but I got an answer that I understand Originally trying to create a temporary text file, and writing it here about the error in this code:

  (streamer output = new streamer (create file (GetTemporaryDirectory ())))  

and getTemporaryDirectory method:

  public string GetTemporaryDirectory () {string tempDirectory = Path.Combin E (Path.GetTempPath ()), path. GetRandomFileName ()); String tempFile = path. Change Extension (tempDirectory, ".txt"); Directory.CreateDirectory (tempfile); Return TempFile; }  

and last but not least error:

dir = C: \ Users \ Jack Givens \ AppData \ Local \ Temp \ 5ftxwy31.txt The first chance of a type 'system.UnauthorizedAccessException' was an exception in mscorlib.dll, an unrestricted exception of type 'System.UnauthorizedAccessException' type in mscorlib.dll Additional information: Path 'C: \ User \ Jack Gavins \ AppData \ Local \ Temp \ 0lpe1k5t.txt is denied.

If someone can tell me what is wrong with my code and what I have to do to fix it, I appreciate it. Side note: Sorry for the dirty code, I'm starting a bit :)

You Create your file name on the directory is now present in a folder that is trying to call File.Create just remove the Directory.CreateDirectory (tempFile) ; The line (It is not necessary that the folder is guaranteed to exist) and your code should work.


Comments

Popular posts from this blog

c# - SignalR: "Protocol error: Unknown transport." when navigating to hub -

class - Kivy: how to instantiate a dynamic classes in python -

python - mayavi mapping a discrete colorbar on a surface -