Quantcast
Channel: How to get relative path from absolute path - Stack Overflow
Viewing all articles
Browse latest Browse all 25

Answer by Dragos Durlut for How to get relative path from absolute path

$
0
0

In ASP.NET Core 2, if you want the relative path to bin\Debug\netcoreapp2.2 you can use the following combination:

using Microsoft.AspNetCore.Hosting;using Microsoft.Extensions.Configuration;public class RenderingService : IRenderingService{    private readonly IHostingEnvironment _hostingEnvironment;    public RenderingService(IHostingEnvironment hostingEnvironment)    {    _hostingEnvironment = hostingEnvironment;    }    public string RelativeAssemblyDirectory()    {        var contentRootPath = _hostingEnvironment.ContentRootPath;        string executingAssemblyDirectoryAbsolutePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);        string executingAssemblyDirectoryRelativePath = System.IO.Path.GetRelativePath(contentRootPath, executingAssemblyDirectoryAbsolutePath);        return executingAssemblyDirectoryRelativePath;    }}

Viewing all articles
Browse latest Browse all 25

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>