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
1
Question by Jobaby · May 25, 2012 at 06:39 PM · filexml

How to download a file and store it on a tablet

Hi everyone,

I have a huge problem. I am currently working on a game on iPad2 and Android tablets. I need to download a file (an xml file, to be precise) from an url address, and store it on the device for later use (reading, parsing, whatever).

I have read that I could use persistentDataPath -- which I have done (as shown below) -- but this doesn't work for the iPad, while being perfectly ok for the Android tablet. Here is a snippet of my code:

 WWW www = new WWW("INSERT URL HERE");
 yield return www;
 XmlDocument xmlDoc = new XmlDocument();
 xmlDoc.LoadXml(www.text);
 if (iPhoneSettings.generation == iPhoneGeneration.iPad2Gen){
   xmlDoc.Save(Application.persistentDataPath + "/database.xml");
 }
 else if(Application.platform == RuntimePlatform.Android){
   xmlDoc.Save(Application.persistentDataPath + "/database.xml");
 }
 else{ // for PC applications
   xmlDoc.Save(Application.dataPath + "/StreamingAssets/database.xml");
 }

I really can't see what's wrong with this.

Thank you in advance!

Bye.

EDIT: Just added a missing line in the code. Can anyone help me? :)

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 BerggreenDK · Oct 24, 2012 at 09:54 AM 0
Share

did you ever solve this one?

1 Reply

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

Answer by Fattie · Oct 24, 2012 at 11:27 AM

here's a fragment for a PNG, it may help you ...

 function _folder():String
     {
     return Application.persistentDataPath + "/fattie";
     }
 function _filename( n:int ):String
     {
     return "picture" + n + ".png";
     }
 function _fullFilename( n:int ):String
     {
     return _folder() + "/" + _filename(n);
     }
 
     var bytes:byte[];
     bytes = sillyPhoto.EncodeToPNG();
     System.IO.File.WriteAllBytes( _fullFilename( 13 ), bytes );
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

8 People are following this question.

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

Related Questions

Why XmlTextReader become so slowly in Unity? 0 Answers

How do i load Xml and assign variables to player in C#? 1 Answer

Opening XML file which determines the game 0 Answers

StreamWriter problems in Unity 5? 0 Answers

Missing additional configuration xml files after build 0 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