Question

I need to read, edit and save one xml file. In other words, I want to write again over the same file and not to create a new xml file. Reading and editing parts work, but not the saving.

The Linq-to-Xml code for saving is simply:

doc.Save(this.Path);

This works in iPhone Simulator but throws System.UnauthorizedAccessException on the device. The xml file is decorated as "content" in MonoDevelop.

Any help appreciated.

/pom

Was it helpful?

Solution

You need to save the file into one of the locations that you have write permissions on:

The /Document directory can be retrieved using: var documents = Environment.GetFolderPath (Environment.SpecialFolder.Personal);

Our "How To Store Files" page has more details:

http://wiki.monotouch.net/HowTo/Files/HowTo:_Store_Files

OTHER TIPS

You are only allowed to save into your application's document directory. You can get it like this:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 

What is the value of this.Path?

var documents = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
var document = Directory.GetFiles(documents);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top