Cant figure out why i’m getting this exception, my c:\ disk has complete read/write permissions for all users and running UNITY as an administrator does not help so I assume its not a permissions issue.
full error:
UnauthorizedAccessException: Access to the path 'C:' is denied.
System.IO.FileStream…ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.IO/FileStream.cs:259)
System.IO.FileStream…ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
(wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int)
System.IO.File.Create (System.String path, Int32 bufferSize) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.IO/File.cs:135)
System.IO.File.Create (System.String path) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.IO/File.cs:130)
System.IO.File.WriteAllBytes (System.String path, System.Byte bytes) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.IO/File.cs:594)
Program.Start () (at Assets/Scripts/Program.cs:28)
code:
using System;
using System.IO;
using System.Net;
using UnityEngine;
public class Program : MonoBehaviour
{
public void Start()
{
System.Net.ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
// Create web client simulating IE6.
using (WebClient client = new WebClient())
{
client.Headers["User-Agent"] =
"Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) " +
"(compatible; MSIE 6.0; Windows NT 5.1; " +
".NET CLR 1.1.4322; .NET CLR 2.0.50727)";
// Download data.
byte[] arr = client.DownloadData("https://docs.google.com/file/d/0B_jZsNBM3OCeX21oaEZzUTh0enM/edit?usp=sharing");
// Write values.
Debug.Log("--- WebClient result ---");
Debug.Log(arr.Length);
File.WriteAllBytes("C:\\", arr);
}
}
}