Where did App_Data go?
# help-with-umbraco
r
I'm wondering why Umbraco has removed the App_Data folder from the newer versions and where should I now add any data files that I use within the application. They shouldn't be in wwwroot Can I still add my own App_Data folder in the project or should I name it something else. It's for import files in this case, but may want to store temporary files in the future.
s
umbraco\Data
is where we put our stuff these days
you can add any folder you want 🙂
a
You may use these to get the path of the data directory (and temp directory):
Copy code
csharp
@using Microsoft.AspNetCore.Hosting
@using Umbraco.Cms.Core.Extensions
@using Umbraco.Cms.Core
@inject IWebHostEnvironment WebHostEnvironment

@{

    <h3>Data Directory</h3>
    <pre>@AppDomain.CurrentDomain.GetData("DataDirectory")</pre>
    <pre>@WebHostEnvironment.MapPathContentRoot(Constants.SystemDirectories.Data)</pre>

    <h3>TEMP Directory</h3>
    <pre>@WebHostEnvironment.MapPathContentRoot(Constants.SystemDirectories.TempData)</pre>

}
Umbraco sets the value for
@AppDomain.CurrentDomain.GetData("DataDirectory")
, so you can use that for getting the data directory - or use Umbraco's constant.
Constants.SystemDirectories.Data
is
~/umbraco/Data
as suggested by Sebastiaan
Constants.SystemDirectories.TempData
is
~/umbraco/Data/TEMP
s
These are in the default
.gitignore
file by the way, so if you need to store data that should move accross environments you probably want to make your own directory for it.
The reason it's gone, by the way, is because it was a .NET framework convention. It played nicely with IIS. https://stackoverflow.com/questions/528858/what-is-the-app-data-folder-used-for-in-visual-studio However, now that dotnet is cross-platform, you can't know what webserver it will run on, so those conventions are no longer useful.
k
I don't know if it changes the 'MapContentRoot' method. but the temp folder can be moved, and not actually be in the site folder at all (this is done when on azure, because the local temp folder is quicker than the disk that the site is on).
So - i do this.
Copy code
cs
_tempPath = Path.GetFullPath(
       Path.Combine(hostingEnvironment.LocalTempPath, "my-folder"));
then you get it from the current executing environment, and if its moved you get the moved folder.
(but
MapPathContentRoot
might do it 🤷‍♀️ - but i am not actually sure.
a
My example uses Umbraco's constants, so if doing that, I guess
MapPathContentRoot
will be incorrect
20 Views