Helper folders in MAC

Dani_S 3,126 Reputation points
2024-05-30T11:52:15.06+00:00

Hi,

I need for my app in mac some helpers folders to :

1.for log file

2.for dwnload files

....

where to put them ?

I nee absoulth path for them to read from code of mac app.

Thanks,

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,091 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 59,546 Reputation points
    2024-05-30T21:58:00.1666667+00:00

    the typical folder for application data files not meant for the user is "~/Library". The Maui file helper should have this path.

    var libPath = FileSystem.AppDataDirectory;

    generally you would use the "~/Library/Application Support/<appname>" folder. if you want to access the downloads folder is is "~/Downloads". Maui does not have a helper for this.

    in objective-c to get the value of "~/" its: NSHomeDirectory() or FileManager.default.homeDirectoryForCurrentUser -> url.

    note: because Maui apps are Catalyst apps, the folders will typically be the sandbox folders.


  2. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 28,071 Reputation points Microsoft Vendor
    2024-06-05T07:41:56.9+00:00

    Hello,

    val fullPath= Path.Combine(libPath, "Application Support/MyApp/log.txt);

    Please check if there is a MyApp directory under Application Support. If not, you have to create one, please refer to the following code:

               var fullPath3 = Path.Combine(libPath, "Application Support/MyApp");
                NSFileManager.DefaultManager.CreateDirectory(fullPath3, true, null);
                var fullpath = Path.Combine(fullPath3, "log.txt");
     
                File.WriteAllText(fulpath, CurrentContents); 
    

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.