System.UnauthorizedAccessException occurs under Admin privileges with full access to folder

I'm all out of ideas on fixing an "Access Denied" issue on Windows 8.1...

I'm building a console app in Visual Studio under Administrative mode and my app is simply trying to do the following:

using System.IO; namespace CommandCenterScriptLauncher { class Program { static void Main(string[] args) { try { Console.WriteLine("The argument passed was " + args[0] + "."); Console.ReadLine(); File.WriteAllText(@"C:\Users\Matt\Music\target", "TEXT FILE BODY WITH ARG: " + args[0]); } catch { Console.WriteLine("No arguments were passed."); Console.ReadLine(); File.WriteAllText("C:\\Users\\Matt\\Music\\target", "TEXT FILE BODY WITH NO ARGS"); } } } }

Not only am I running in Admin mode which isn't helping, but the folder itself is NOT read only, and ALL USERS on the Security tab for the target folder have been granted FULL CONTROL.

What else am I missing here?!

--------------Solutions-------------

You need to pass in a filename to File.WriteAllText. Right now, it looks like you are trying to write to a directory. That won't work.

Can you write in another location?. Windows for some reason prevent for writing on system folders. Try something like 'c:/Test/yourFile.txt'.

Check also UAC is disabled.

Category:c# Time:2018-10-30 Views:0
Tags: .net

Related post

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 3.715 (s). 14 q(s)