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 PClabs · Jun 15, 2011 at 07:24 PM · fileifiostatement

Create file in correct directory

Hey Great community of Unity Answers. When a new user account ("Actually work order") is created, it creates a directory for that given user. Then I want it to create a Text File in that directory with all the given information.

The Directory gets created just fine. With the help of Unity Answers, I was able to create and write to a Text File. However, I cant figure out, how to point the text file in the directory it just created. It just overwrites the same file over and over again. I tried an If statement but I am not a good programmer. This is my first real project. More of a learning experience than anything else. Here is my code so far for a work order. The code in question is at the bottom.

 var workorderidGUI = "001";
 var firstnameGUI = "First Name";
 var lastnameGUI = "Last Name";
 var custHomeNBRGUI = "000-000-0000";
 var custCellNBRGUI = "000-000-0000";
 var custStreetGUI = "";
 var custCityGUI = "";
 var custSTGUI = "";
 var custZIPGUI = "";
 
 var compDiag = "Enter Described Problem or Initial Troubleshooting.";
 
 
 function OnGUI () {
 
 workorderidGUI = GUI.TextField (Rect (885, 80, 40 , 20), workorderidGUI);
 firstnameGUI = GUI.TextField (Rect (125, 80, 120, 20), firstnameGUI);
 lastnameGUI = GUI.TextField (Rect (265, 80, 120, 20), lastnameGUI);
 custHomeNBRGUI = GUI.TextField (Rect (135, 130, 100, 20), custHomeNBRGUI);
 custCellNBRGUI = GUI.TextField (Rect (135, 160, 100, 20), custCellNBRGUI);
 custStreetGUI = GUI.TextField (Rect (440, 130, 300, 20), custStreetGUI);
 custCityGUI = GUI.TextField (Rect (440, 160, 100, 20), custCityGUI);
 custSTGUI = GUI.TextField (Rect (580, 160, 30, 20), custSTGUI);
 custZIPGUI = GUI.TextField (Rect (680, 160, 60, 20), custZIPGUI);
 
 compDiag = GUI.TextField (Rect (60, 250, 360, 300), compDiag);
 
 
 if (GUI.Button (Rect (25, 650, 120, 30), "Save Work Order")) {
 
     //create Username
 
     usernameGUI = firstnameGUI.Substring(0,1) + lastnameGUI.Substring(0,1) + workorderidGUI.Substring(0,1) + custHomeNBRGUI.Substring(0,1) + custCellNBRGUI.Substring(0,1) + custStreetGUI.Substring(0,1) + custCityGUI.Substring(0,1) + custSTGUI.Substring(0,1) + custZIPGUI.Substring(0,1);
 
     //create Folder
     if (!Directory.Exists ("C:/Data/" + firstnameGUI)) {
 
         Directory.CreateDirectory ("C:/Data/" + firstnameGUI);
     }
     //Create Text file.
     //save to textfile
         System.IO.File.WriteAllText("C:/Data/data.txt", lastnameGUI + ", " + firstnameGUI + "," + workorderidGUI  + "," + custHomeNBRGUI  + "," + custCellNBRGUI  + "," + custStreetGUI  + "," + custCityGUI  + "," + custSTGUI  + "," + custZIPGUI);
     }
 
 }
Comment
Add comment · Show 1
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 PClabs · Jun 15, 2011 at 07:25 PM 0
Share

If you want a better understanding of the application, I have included a alpha build: http://www.megaupload.com/?d=Z$$anonymous$$$$anonymous$$SOA7$$anonymous$$

3 Replies

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

Answer by almo · Jun 15, 2011 at 07:30 PM

Your WriteAllText statement says the path to write to is "C:/Data/data.txt". If you want to write the files somewhere else, you have to change that.

Like System.IO.File.WriteAllText("C:/Data/" + firstnameGUI + "/data.txt", bunch of data...);

Comment
Add comment · Show 2 · 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 PClabs · Jun 15, 2011 at 07:32 PM 0
Share

I thought I tried that, but must of typed it wrong. that works! Thank you almo.

avatar image almo · Jun 15, 2011 at 07:35 PM 0
Share

Sure. ^_^

avatar image
-2

Answer by UnityNewbieTawin · Mar 26, 2014 at 06:19 PM

hello, newbie here

can you help me.. i got an error

No appropriate version of 'System.IO.File.WriteAllText' for the argument list '(String, String, boolean)' was found.

when i run your codes.. somebody help me -_-

Comment
Add comment · Show 3 · 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 jahroy · Mar 26, 2014 at 11:35 PM 0
Share

The first step to solving such problems is always to check the documentation:

WriteAllText documentation

The first thing you should notice is that there are two versions of this method: the first version takes two strings as parameters. The second version takes three parameters (the first two are strings and the third is an Encoding object).

The error message is telling you that there is no method named WriteAllText that takes two strings and a boolean.

To fix your error, either pass two strings OR two strings and an Encoding type to the method named WriteAllText.

By the way, you should not create a new answer when you have a question... Please use comments in s$$anonymous$$d.

avatar image jahroy · Mar 26, 2014 at 11:50 PM 0
Share

Also, if your app runs on the web, you CANNOT use this method for security purposes.

If you're not using a webplayer, make sure you import the System.IO namespace.

avatar image Bunny83 · Mar 27, 2014 at 02:58 AM 0
Share

@jahroy: Since you pointed out the error, you might want to fix your answer as well ^_^.

To append text you can use AppendAllText

avatar image
0

Answer by jahroy · Jun 15, 2011 at 07:31 PM

Try this in stead:

     System.IO.File.WriteAllText("C:/Data/data.txt", someString, true);

You can add an extra boolean parameter to File.WriteAllText() to specify whether or not you would like to append to the file if it already exits.

That would be if you want to write all your data to the same file "C:/Data/data.txt".

If you want to write to different files, you need to change the file name like the other answer indicates.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

My backpack script doubt 0 Answers

Search for files on android 2 Answers

Destorying despite IF Statement 1 Answer

parsing csv file 2 Answers

Script Performance Questions 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