WinUI 3 Desktop App - working directory, deploying content

Gregorij Kurillo 21 Reputation points
2021-12-18T01:26:08.31+00:00

Hello! I'm developing a WinUI 3 app for desktop. When trying to write/read a file, I've noticed that the current working directory for the app is always Windows/system32. I'm trying to understand how the current working directory works for WinUI desktop, specifically how one deploys a custom file that should be accessible to the app but also to the user directly (e.g. for app configuration)? I can add a file to the Content and it will get deployed but where exactly does that file end up? I know I can read/write files anywhere in the desktop app but how would I deploy a content file automatically within the Visual Studio project/package at runtime or installation to a custom location?

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
783 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 85,126 Reputation points
    2021-12-18T05:25:38.667+00:00

    As WinUI uses .NET 5, you can get the application directory with, for example :

     string sDirectory = AppDomain.CurrentDomain.BaseDirectory;
    

    For user files, you should store them like other Desktop applications do, in a subdirectory in %LOCALAPPDATA% :

    string sLocalAppdata = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
    
    0 comments No comments

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.