1

I am building a .netcore library.And testing it using .net core console application. I have the following folder structure inside Library:

WrapperLib
 |->FolderXYZ
    |->FileABC.txt
 |->ControllerClass.cs

I am trying to access FileABC.txt from ControllerClass.cs using relative path "\FolderXYZ\FileABC.txt". But when I run application using .net core console application, by default the program is taking running application's home directory as Current working directory. How can I solve this and give correct reference to FileABC.txt from ControllerClass.cs

vssl
  • 61
  • 3

1 Answers1

0
 var location = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "FolderXYZ\\FileABC.txt");

Also dont forget to set "Copy to output directory" to "Always" or "Copy if newer".

Alternatively you can set the "Build action" as "Embedded resource" (thus it will become part of your compiled assembly) and then read it using the stream like this.

igorc
  • 2,024
  • 2
  • 17
  • 29