Where can I find the MyDocuments folder on iPhone Simulator?

Viewed 2470

I created a text file named Write.txt in the Documents folder in a Xamarin.iOS app. After that I was able to read its content to the console.

var documents = 
 Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var filename = Path.Combine(documents, "Write.txt");

File.WriteAllText(filename, "Write this text into a file");
var text = File.ReadAllText(filename);

Console.WriteLine(text);  // prints out correctly

The problem is, that I can't found this file on the iPhone simulator's Files app. There is no Documents folder anywhere, and I don't get any results if I search for the filename.

(Yes, I'm new in iOS, so sorry if the question is stupid :) )

2 Answers

See Building Great Document-based Apps in iOS 11.

If you want to see it in the files app, you’ll want to set the following value in your Info.plist:

  • “Supports Document Browser” (UISupportsDocumentBrowser)

Or

  • “Application supports iTunes file sharing” (UIFileSharingEnabled); and
  • “Supports opening documents in place” (LSSupportsOpeningDocumentsInPlace)

I just run your code and it all works well on my side. The file you written to was successfully opened. I guess you might have some wrong step when opening the folder, let me show you how to do it:

1.I run your code and then print the file path(the filename in your code), on my side it is:

/Users/myName/Library/Developer/CoreSimulator/Devices/0F06FD18-4307-4102-8A30-5EB017A4BD26/data/Containers/Data/Application/20A0294B-36C5-484F-8BD1-B69B977BA378/Documents/Write.txt

2.Go to your mac --> select Finder --> Then open the Go menu --> Click Go to Folder

screenShot

3.Paste your path to the text box:

enter image description here

4.Click Go and you will see the file:

enter image description here

Some folders are hidden in your system so you can't see them when search for the filename. Feel free to ask me if you have any question.

Related