- Home /
read write xml file on ipad ,Access denied
i want to save player information to xml file ,but something is wroing , i need your help
this is the error information: UnauthorizedAccessException:
Access to the path "/var/mobile/Applications/76720F65-B39A-4D02-934D-6CBD9E455B3A/bodhirun.app/Data/Raw/Collection/MyCollections.xml" is denied. at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in :0 at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share) [0x00000] in :0 at System.Xml.XmlTextWriter..ctor (System.String filename, System.Text.Encoding encoding) [0x00000] in :0 at System.Xml.XmlDocument.Save (System.String filename) [0x00000] in :0 at CollectionControl.SaveCollectionItem (System.String itemType, Int32 itemID) [0x00000] in :0 at CollectionControl.Update () [0x00000] in :0
this is my code:
 string filepath = Application.streamingAssetsPath + "/Collection/MyCollections.xml";
         XmlDocument xmlDoc = new XmlDocument();
         
         if( File.Exists(filepath) )
         {
             xmlDoc.Load (filepath);
             XmlElement root = (XmlElement)xmlDoc.SelectSingleNode("Collections");
             
             
             bool isNewElement = true;
             foreach (XmlElement xe in root.ChildNodes)
             {
                 int id = int.Parse(xe.InnerText.Split('_')[1]);
                 string type = xe.InnerText.Split ('_')[0];
                 if(itemType == type && id == itemID)
                 {
                     isNewElement = false;
                     int num = int.Parse(xe.InnerText.Split ('_')[2]) + 1;
                     xe.InnerText = type + "_" + itemID.ToString() + "_" + num.ToString();
                 }
             }
             
             if( isNewElement )
             {
                 XmlElement new_collection = xmlDoc.CreateElement ("item");
                 new_collection.InnerText = itemType + "_" + itemID.ToString() + "_1";
                 root.AppendChild(new_collection);    
             }
             
         }
         else
         {
             XmlElement root = xmlDoc.CreateElement ("Collections");
             XmlElement new_collection = xmlDoc.CreateElement ("item");
             new_collection.InnerText = itemType + "_" + itemID.ToString() + "_1";
             root.AppendChild(new_collection);
             xmlDoc.AppendChild(root);
         }
         
         xmlDoc.Save(filepath);
Your answer
 
 
             Follow this Question
Related Questions
[Android] StreamingAsset problems with XML files 2 Answers
Work with XML hidden for the user? 1 Answer
How to check the path on Android 0 Answers
Application.streamingAssetsPath not working with WebGL build 0 Answers
A node in a childnode? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                