At this moment I am writing a ASP.NET Core web application that should be able to run on Windows and Linux (Ubuntu 16.04). I have some data I want to store, but it is so little, using a database would be a huge waste of performance. Not to mention the installation procedure would be twice as long.
That's why I want to save this information in a file. In .NET Framework I would use something like Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
to get a directory where I can store my application files. Unfortunately this method is not available in .NET Core 1.1.
Is there any way to get a folder to write to, without hardcoding it?
Below is an example of the data I want to write. There would only be about 5 devices at any time in 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>
NET Core is cross-platform. It runs on Windows, OS X and multiple distributions of Linux. It also supports different CPU architectures. We're adding more Linux distribution and CPU architecture support with the eventual goal of .
So, to the "cross-platform", it means the server side, instead of the client side (access the web page via browser). For the . Net framework application, it runs/host primarily on Microsoft Windows. But Asp.net core application can run/host on Windows, OS X, and multiple distributions of Linux.
Kestrel is a cross-platform web server for ASP.NET Core. Kestrel is the web server that's included and enabled by default in ASP.NET Core project templates. Kestrel supports the following scenarios: HTTPS. HTTP/2 (except on macOS†)
I usually go with a folder relative from the IHostingEnvironment.ContentRootPath
. It provides a cross-platform way to access files from the root of your application. You could even call it App_Data
if you'd like.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With