• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by LividRabbit · Oct 15, 2013 at 09:16 PM · c#

UnauthorizedAccessException: Access to the path 'C:\' is denied.

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);
         }
     }
 }
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Oct 15, 2013 at 09:44 PM 0
Share

Have you tried

 import System.IO;
avatar image LividRabbit · Oct 15, 2013 at 10:47 PM 0
Share

It was already in the source

avatar image LividRabbit · Oct 16, 2013 at 07:45 PM 0
Share

and anyhow, this is a runtime error, not a compiler error.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by billykater · Oct 16, 2013 at 08:34 PM

If you use File.WriteAllBytes you have to specify a file path. You are trying to write bytes directly to a "directory" which is not possible. This problem will be fixed if you specify a valid file path.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Renderer on object disabled after level reload 1 Answer

Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer

Initialising List array for use in a custom Editor 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges