0

Good day. I need to get path of a specific .txt file. From Service class i can call AppContext.BaseDirectory and it get me path to folder where placed .exe:

C:\Users\XXX\Documents\Visual Studio 2015\Projects\MyProject\src\MyProject\bin\Debug\netcoreapp1.0"

But what i need to do if i need to get file from path:

`C:\Users\XXX\Documents\Visual Studio 2015\Projects\MyProject\src\Core\Common\MyFile.txt`

Use fixed path - it's bad solution, i think

Evgeniy175
  • 324
  • 1
  • 9
  • 23

1 Answers1

0

you need to use something like this

Server.MapPath("~/files/myFile.txt") 

which will get you to your file as long as your folder structure (based on this example) is

Root | Files | myFile.txt

Edit

my bad, there is no Server.MapPath in ASP.Net Core, take a look at this and this should give you the concept you need in addition with my answer here

how to get server.MapPath in asp.net core from inside a helper

Community
  • 1
  • 1
Simon Price
  • 3,011
  • 3
  • 34
  • 98
  • What 'Server' you talk about? `Microsoft.AspNetCore.Server` or `Microsoft.AspNetCore.Hosting.Server` not contains method MapPath – Evgeniy175 Nov 26 '16 at 14:07