Forum Discussion
ionoy
Mar 29, 2022Copper Contributor
Can I write to wwwroot with MAUI/Blazor
I need to create dynamic images in my wwwroot directory to display them in Blazor component. Is it possible? How do I get a writable path if there is no more host environment in the latest version?
- Adrees_UmerCopper ContributorYou can indeed access the wwwroot directory in a Blazor or MAUI app and get its path. This can be quite handy for various scenarios, like dynamically generating and serving images. To retrieve the wwwroot path, you can use the following code:
string rootPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot");
However, it's essential to note that the specific path may vary depending on your environment. When running in debug mode, the path might look like this:
\\bin\\Debug\\net7.0-windows10.0.19041.0\\win10-x64\\AppX\\wwwroot
But when you upload your application or run it in release mode, it will automatically reference the files from the wwwroot folder within your project.
This method allows you to access the wwwroot directory and manage its contents programmatically, making it a useful feature for serving dynamic content in your Blazor or MAUI app.