Home > Articles > Details

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?


Please 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;
        }

If you log in, you will be notified when someone leaves a comment.

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


© 2022 - ErnesTech - Privacy