Alternative to Environment.SpecialFolder.Personal in UWP?

larry leach 91 Reputation points
2020-12-11T02:08:02.107+00:00

For IOS and Android, Environment.SpecialFolder.Personal gives an accessible folder (I'm creating a log file there). However, in UWP, Environment.SpecialFolder.Personal gives something like 'D:\Documents' that Xamarin Forms can't write to. Hopefully I don't have to deal with something like Windows.Storage - that is, special casing all the code for UWP. Frankly, UWP is already buggy enough, but I would really like to include it in the development. Is there something simple I'm missing (for transparency...I'm new to Xamarin)? Thanks in advance for any help.

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,861 Reputation points
    2020-12-11T06:42:50.99+00:00

    Hello larryleach-7993, Welcome to Microsoft Q&A,

    Environment.SpecialFolder.Personal gives something like 'D:\Documents' that Xamarin Forms can't write to

    The problem is Environment.SpecialFolder.Personal was under system namespace that can't be access in UWP platform. for your requirement, we suggest you use File System Helpers to get app's local folder that could access with path directly.

    var localfolder = FileSystem.AppDataDirectory;  
    File.WriteAllText(localfolder + "/log.text", "hello");  
    

    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