Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by Sebas · Nov 03, 2009 at 07:52 AM · errorpathfile-iodirectory

Saving File in new directory - Unauthorized Access Exception

I am trying to save a text file to a newly created directory. I get the following error:

UnauthorizedAccessException: Access to the path 'C:\Data\FS031109' is denied. System.IO.FileStream..ctor (System.String name, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) System.IO.FileStream..ctor (System.String name, FileMode mode, FileAccess access, FileShare share) ...

I've seen on the forums that iPhone applications can only read/write to certain directories, but I am not trying to work on an iPhone application. It's essential that I can create a new folder with a custom name (i.e. username) and save a text file there. Any suggestions? Which directories can I write to? Where can I create new directories, what's restricted?

Many thanks!

Here's what I'm trying to do. :

var firstnameGUI = "First Name"; var surnameGUI = "Surname"; function OnGUI () {

firstnameGUI = GUI.TextField (Rect (25, 80, 150, 30), firstnameGUI); surnameGUI = GUI.TextField (Rect (25, 115, 150, 30), surnameGUI);

if (GUI.Button (Rect (25, 350, 120, 30), "Save User")) {

 //create Username
 var date = DateTime.Now.ToString("ddMMyy");
 usernameGUI = firstnameGUI.Substring(0,1) + surnameGUI.Substring(0,1) + date;

 //create Folder
 if (!Directory.Exists ("C:/Data/" + usernameGUI)) {

     Directory.CreateDirectory ("C:/Data/" + usernameGUI);
 }

 //save to textfile
 TextFile.SaveTextFile ("C:/Data/" + usernameGUI, "test");
 }

}

Comment
Add comment
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

1 Reply

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

Answer by Sebas · Nov 03, 2009 at 08:47 AM

Well, that much about my first question on here. I think I can answer it myself. I forgot to specify the filename. While the path itself was correct, I forgot to add "/" + usernameGUI + ".txt" to the end. Writing to a directory and not to a file most likely won't work.

TextFile.SaveTextFile ("C:/Data/" + usernameGUI + "/test.txt", "test");

--> works
I thought I tried that before, but it seems like I was missing a "/"or something. Thanks anyways.

Sebas

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Installing Unity on a multi-user environment, how to set permissions? 0 Answers

Why is my file path invalid? 2 Answers

delete files from app(documents directory) 1 Answer

.dll files will not be loaded in latest unity version 2 Answers

How to set my ADB path ? pls. 3 Answers


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