Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 grimmy · Oct 05, 2011 at 09:52 AM · textfilecreate

Why do I get the error - 'WriteAllText' is not a member of 'System.IO.File

I am trying to create a simple text file but I'm getting the above error.

All I am doing is the following:

 System.IO.File.WriteAllText("C:/Users/Simon/Desktop/exampleSaveData.txt", stringToPost);

This post is related.

Comment
Add comment · Show 2
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 syclamoth · Oct 05, 2011 at 09:54 AM 0
Share

Have you included System.IO at the top of your file? Are you sure you have spelled everything correctly?

avatar image grimmy · Oct 05, 2011 at 10:00 AM 0
Share

I have import System; at the top of the script. I am using Javascript. This is the correct syntax right?

2 Replies

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

Answer by arkon · Oct 05, 2011 at 10:57 AM

Check your game target, I had the same problem. You can't use WriteAllText if the target is the web. There doesn't seem to be a unity stub for it either so you need to @ifdef it out on web targets.

Comment
Add comment · Show 4 · 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
avatar image CHPedersen · Oct 05, 2011 at 11:28 AM 2
Share

That's exactly what he's saying. :) Think about it for a second - Webplayers are executed on the user's own machine, like Flash and Silverlight applications are. How would you like programmers to be able to write programs that you download in a website and execute locally, which put whatever files they want at whatever location they want, on your computer?

I could write a program that executes the following:

int count = 0;

while(true) { System.IO.WriteAllText("C:/Users/Simon/Desktop/exampleSaveData" + count+".txt", "Hahahahaha, screw you, this is a billion files on your desktop"); count++; }

Would you like to run that? ;) That functionality is limited in a web context is a very, very, VERY good thing.

avatar image grimmy · Oct 05, 2011 at 11:28 AM 0
Share

Yeah that works cheers. I switched to standalone to extract my text file.

avatar image grimmy · Oct 05, 2011 at 01:46 PM 0
Share

Thanks Christian, I understand that but as I'm running through the editor locally I assumed that wouldn't be a problem or perhaps give me some kind of useful warning/error. But I know now.

avatar image arkon · May 29, 2012 at 04:34 AM 0
Share

I don't $$anonymous$$d the fact it's not there but there should be a stub, so the code compiles and maybe just outputs a message too tell you its not implemented. I hate littering my code with #if defs for this reason.

avatar image
0

Answer by drudiverse · Aug 24, 2015 at 09:28 AM

Ok switch to standalone and not web player mode fixes it...

I just had the error happening in one script and not another with the same line.

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

7 People are following this question.

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

Related Questions

How do you create a folder in c#? 3 Answers

Trouble creating a text file 4 Answers

How can I get game data from a specified file? 0 Answers

Create GUIText from Javascript 3 Answers

Directory.CreateDirectory not working 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