Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code a File Path that works in both OSX and Windows (dotnet core)

I have to save files in my dotnet core application. I originally developed in windows; but when I ported the code to try developing on a mac, the file path is no longer valid (i.e. "c:\content..."). Is there a way to reference a file path, in my code, that will work in both situations? We deploy to azure... so the windows file path must there too.

FileInfo fileInfo = new FileInfo("c:\\Content\\SalesOrderOutput\\" + 
      fileName.txt);
FileStream stream = fileInfo.OpenWrite();
like image 317
GolferGeek Avatar asked Jan 29 '23 13:01

GolferGeek


1 Answers

Use Path.Combine method like this:

internal static readonly FileInfo Mp4WithAudio = new FileInfo(Path.Combine(Environment.CurrentDirectory, "Resources", "input.mp4"));

Code from https://github.com/tomaszzmuda/Xabe.FFmpeg/blob/c8cc4232b5afa2860ede3be63a680d754ed73002/Xabe.FFmpeg.Test/Resources.cs

like image 189
Tomasz Żmuda Avatar answered Feb 05 '23 17:02

Tomasz Żmuda