question

KhaiFLPM-7217 avatar image
0 Votes"
KhaiFLPM-7217 asked JarvanZhang-MSFT edited

Xamarin Forms iOS Download Path

My app can download file by getting the url, but the thing is, how to point the downloaded file into iPhone Files app. I try below code, it run smoothly without any error, but I dont know wheres the downloaded file located. I believe many developers facing the same issue for ios.

                 string pathToNewFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), folder);
                 Directory.CreateDirectory(pathToNewFolder);

                 WebClient webClient = new WebClient();
                 webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
                 string pathToNewFile = Path.Combine(pathToNewFolder, Path.GetFileName(url));
                 webClient.DownloadFileAsync(new Uri(url), pathToNewFile);


Environment.GetFolderPath(Environment.SpecialFolder.Personal) does not point to Files app. For image, SaveToPhotosAlbum method seems good and success, but now I want to download file such pdf/excel, etc.

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered JarvanZhang-MSFT edited

Hello,​

Welcome to our Microsoft Q&A platform!

I try below code, it run smoothly without any error, but I dont know wheres the downloaded file located

The file will be stored under the 'Documents' folder of the application. The Environment.SpecialFolder.Personal path will map to: /Documents folder on iOS.

IOS imposes some restrictions on what an application can do with the file system to preserve the security of an application’s data, and to protect users from malignant apps. An application is limited to reading and writing files within its home directory (installed location); it cannot access another application’s files. It's unable to download the file to a folder that does not belong to the application directly.

Check the links:
https://stackoverflow.com/questions/47237414/what-is-the-best-environment-specialfolder-for-store-application-data-in-xamarin
https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/file-system

Best Regards,

Jarvan Zhang



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@JarvanZhang-MSFT
Okay thank you, now I understand. But, how can I access the /Documents folder on my device? I don't know where it's located?

[UPDATE]
I already enable UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace, but still my directory not created :(

[UPDATE 2]
After refer this https://stackoverflow.com/questions/58380409/where-can-i-find-the-mydocuments-folder-on-iphone-simulator, I try to restart my device and my directory finally appeared!! .. together with my previous downloaded files also inside there.. woahh finally, just with restart solved the problem..
Thanks alots @JarvanZhang-MSFT

1 Vote 1 ·

Congrats! And thanks for sharing the solution.

1 Vote 1 ·