Home > Net >  How to change the Current Working Directory of Maui Blazor App
How to change the Current Working Directory of Maui Blazor App

Time:01-02

I have a Maui Blazor Hybrid apps created through Visual Studio 2022. When I access the method GetCurrentDirectory() this returns C:/Windows/system32.

How do I set this to return the path of where the wwwroot folder is of my project?

CodePudding user response:

First of all, you can use the Directory.SetCurrentDirectory() to set the application's current working directory to the specified directory according to this method's official document.

And then, you can get the wwwroot folder by the following code:

var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot");

So you can change the Current Working Directory by the following code:

Directory.SetCurrentDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot"));
  • Related