Cross-platform way to get the directory for application data in .NET Core 1.1

I am currently writing an ASP.NET Core web application that should run on Windows and Linux (Ubuntu 16.04). I have some data that I want to store, but it is so small, using a database will be a huge loss of performance. Not to mention that the installation procedure will be twice as long.

That is why I want to save this information in a file. In the .NET Framework, I would use something like Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)to get a directory in which I can store application files. Unfortunately, this method is not available in .NET Core 1.1 .

Is there a way to get a folder for recording without hard coding?

Below is an example of the data I want to write. There will be only about 5 devices on this list.

<devices>
    <device>
        <id>0</id>
        <name>xxx</name>
        <physicaladdress>yyyyyyyyy</physicaladdress>
    </device>
    ...
    <device>
        <id>5</id>
        <name>xxx</name>
        <physicaladdress>yyyyyyyyy</physicaladdress>
    </device>
</devices>
+4
source share
1 answer

I usually use the folder related to IHostingEnvironment.ContentRootPath. It provides a cross-platform way to access files from the root of the application. You can even call him App_Dataif you want.

+3
source

Source: https://habr.com/ru/post/1672760/


All Articles