Xamarin Forms iOS Download Path

KhaiFMsia 71 Reputation points
2021-03-05T08:09:17.89+00:00

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.

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,971 Reputation points
    2021-03-05T10:43:46.267+00:00

    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://learn.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.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.