如何在ASP.NET Core项目中读取本地文件? [英] How do I read a local file in my ASP.NET Core project?

查看:978
本文介绍了如何在ASP.NET Core项目中读取本地文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想从我的项目中读取本地文件,给定项目目录中的相对路径,我该如何实现?

If I want to read a local file from my project, given a relative path from the project directory, how could I achieve this?

推荐答案

您可以从PlatformServices.ApplicationEnvironment获取ApplicationBasePath.这将使解析相对于您的应用程序基本路径的非绝对路径成为可能.

You can get the ApplicationBasePath from PlatformServices.ApplicationEnvironment. This will make it possible to resolve non-absolute paths relative to your application base path.

这篇关于如何在ASP.NET Core项目中读取本地文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆