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?

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;

Edit this Article Core 3.1 mvc core errors web forms core tutorial Technology published
Was this page helpful?
Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

Your Session is Ending
Login to Continue

© 2021 - ErnesTech - Privacy