- Home /
System Unauthorized
Hello, I have run into some problems in mono. I try and debug the program, and no matter what, it comes up with the same error; Error Error: System.UnauthorizedAccessException: Access to the path 'C:\Users\Craig' is denied. (Error: System.UnauthorizedAccessException) (Assembly-UnityScript-firstpass). The interesting thing is, that folder "Craig" wasn't even created! It looks for the folder, but its not there! I created one to try and circumvent it, but it just said it didn't have access to it. I'm not sure why its doing this. Any help would be appreciated.
Thanks! Craig
Well, if the folder doesn't exist, then that's a good reason why the program can't find it! Find out what part of your program is trying to access this folder, and go from there.
Answer by clunk47 · Dec 09, 2012 at 04:48 AM
Here's a fairly simple script I wrote for you to try out. I have tested and it works. This is a C# script. Let me know if you have any issues and I will resolve them for you. Copy the code below and paste into a new C-Sharp Script named FileTest. Be sure to use : using System.IO when dealing w/ Directory and File objects. This script will check for the directory and file. If something doesn't exist, this script will create it. If the file doesn't exist, the GUI Button will read "Create File". Once you click on the button, it will create the directory and file, then it will read "Write to file". Once you click on the button again, it will write a string to the txt file and open the file with the new appended text.
using System.IO;
using System.Collections;
using UnityEngine;
public class FileTest : MonoBehaviour
{
string ButtonText;
void Update()
{
if(!File.Exists("C:/Users/Craig/Test.txt"))
ButtonText = "Create File";
else if(File.Exists("C:/Users/Craig/Test.txt"))
ButtonText = "Write To File";
}
void OnGUI()
{
if(GUI.Button (new Rect(200, 200, 128, 30), ButtonText))
{
if(!Directory.Exists("C:/Users/Craig"))
{
Directory.CreateDirectory("C:/Users/Craig");
File.Create("C:/Users/Craig/Test.txt");
}
else if(Directory.Exists("C:/Users/Craig") && !File.Exists("C:/Users/Craig/Test.txt"))
File.Create("C:/Users/Craig/Test.txt");
else if(Directory.Exists("C:/Users/Craig") && File.Exists("C:/Users/Craig/Test.txt"))
{
File.WriteAllText("C:/Users/Craig/Test.txt", "Damn, Bro, you just created a file and wrote this text to it :D");
System.Diagnostics.Process.Start ("C:/Users/Craig/Test.txt");
}
}
}
}
Your answer
Follow this Question
Related Questions
The requested feature is not implemented 1 Answer
Unity wont launch 1 Answer
Internal Compiler Error 3 Answers
MonoDevelop Unhandled Exception. MonoDevelop will now close - Mac OSX 1 Answer
Mono Develop start 1 Answer