This is a question I am sure Xcode developers could also answer. I have a screenshot of my code below in Xamarin.
Why am I getting an Unauthorized access exception? I should be able to write to the documents folder right?

Code:
var webClient = new WebClient();
//var documentsFolder = Environment.GetFolderPath (Environment.SpecialFolder.Personal); // iOS 7 and earlier
var documentsFolder = NSBundle.MainBundle.BundlePath;
var fileNameAndPath = Path.Combine (documentsFolder, "verses.xml");
if(!File.Exists(documentsFolder)){
Directory.CreateDirectory(documentsFolder);
if(!File.Exists(fileNameAndPath)){
//File.SetAttributes(fileNameAndPath, FileAttributes.Normal);
File.Create(fileNameAndPath);
//Throws exception here.
}
}
And ERRORs:
Access to the path "/var/mobile/Applications/1F95D694-BBA5-4FB3-AE6C-0C2CDD9DEDD8/comexample.app/verses.xml" is denied
Access to the path '/private/var/mobile/Applications/1F95D694-BBA5-4FB3-AE6C-0C2CDD9DEDD8/Documents/verses.xml' is denied.
I have tried both paths and I get access denied.
You can't write to your app's bundle path, the folder is readonly. I'm also not sure where the Personal folder points to with Xamarin.iOS.
Use this directory, and you can write to it:
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With