0

I am developing an application .NET Core (dotnet) in C# that must run on Windows 10, Linux AND in the Linux subsystem that can be installed in Windows 10.

The problem is that the application must stored files in a common location to let other application use they. That is, others applications (that are clients) must resolved the same path as this application does. So, the same code must be added in all of the clients to know where the files are storage.

I searched a lot and I found this solution:

Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));

This returns me on Windows:

C:\ProgramData

And on Linux:

/usr/share

I like this solution but the problem here is that when the program is running in a Linux subsystem, I want to use a path that can be acceded from applications running on Windows natively.

I know that Windows is mounted in /mnt/c/ in the Linux subsystem but y dont want to have hardcoded paths.

Is there any way to have programatically (running on Linux subsystem) a path in the Windows host? That is, if the program run on Linux natively the path that returns is /usr/share BUT if it is a subsystem, the path that returns is /mnt/c/ProgramData (or something like that).

Thanks!

jjamardo
  • 267
  • 3
  • 9
  • if you haven't a server in common ( thinking as file system service ), maybe you could use Configuration API >> https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/index?view=aspnetcore-2.1&tabs=basicconfiguration – Mate May 11 '18 at 08:29
  • @Mate thanks for the reply. I edited the question because it was not clear enough. As you say, the server in common is my application. The clients must resolve the same path as the server. I tried the Configuration API but I think that it does not resolve my problem. – jjamardo May 11 '18 at 08:46
  • If you have a server, you can expose a method to "get files" and returns a byte[]. Then, only the server needs know the "real" root path. – Mate May 11 '18 at 08:57
  • the *non-recommended* way might be that server returns a "root path" based on client's SO... also you could access via FTP, etc – Mate May 11 '18 at 09:03
  • @Mate I do have a "server" and "clients", but not in the common way, my server write a file, and clients read that file. I do not have a client-server architecture based on pipes, sockets, etc. In fact, all process are in the same pc. For that, all process must resolved the path in a unique way. – jjamardo May 11 '18 at 13:01
  • Ok, then you have one "writer" app and "readers" apps. It's better avoid call them "server and clients". Same pc = same SO if they share a folder. Anyway, check RuntimeInformation.IsOSPlatform(OSPlatform.{x}) >> https://stackoverflow.com/questions/39224518/path-to-localappdata-in-asp-net-core-application?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Mate May 13 '18 at 13:21

0 Answers0