How to get a path to a file in an ASP Dot Net (ASP.Net Core 2.2 ) Core 2.2 Application

Question: How do you get a path to a file in ASP.Net (Dot Net) Core 2.2 Application?

Login to See the Rest of the Answer

Answer: Create a seperate function that will handle that behaviour, creating a separate file is good for modularity and code reusability. See the code below:

public static string GetAbsolutePath(string relativePath)
            FileInfo _dataRoot = new FileInfo(typeof(Program).Assembly.Location);
            string assemblyFolderPath = _dataRoot.Directory.FullName;

            string fullPath = Path.Combine(assemblyFolderPath, relativePath);

            return fullPath;

© 2024 - ErnesTech - Privacy
E-Commerce Return Policy