C# 如何在asp.net core中从多个项目中获取媒体上载的公共项目路径

C# 如何在asp.net core中从多个项目中获取媒体上载的公共项目路径,c#,asp.net,asp.net-mvc,asp.net-core,.net-core,C#,Asp.net,Asp.net Mvc,Asp.net Core,.net Core,为什么我想上传一张图片或视频从管理面板项目,然后访问它从网站项目 我想上传到公共项目文件夹,但无法访问公共项目。 如何在公共项目库文件夹中添加媒体,然后将其用于前端网站 有点老套,但使用IHostingEnvironment获取webroot并用您的公共项目文件夹替换路径 var webRoot = env.WebRootPath; var commonPath = webRoot.Replace("Infodice.NYP.Web.Admin\\wwwroot", &quo

为什么我想上传一张图片或视频从管理面板项目,然后访问它从网站项目

我想上传到公共项目文件夹,但无法访问公共项目。 如何在公共项目库文件夹中添加媒体,然后将其用于前端网站


有点老套,但使用
IHostingEnvironment
获取webroot并用您的公共项目文件夹替换路径

var webRoot = env.WebRootPath;
var commonPath = webRoot.Replace("Infodice.NYP.Web.Admin\\wwwroot", "Infodice.NYP.Web.Common\\Gallery\\ImageGallery");

字符串ParentFolder=Directory.GetDirectories(“Infodice.NYP.Web.Common/Gallery/ImageGallery”);uniqueFileName=Guid.NewGuid().ToString()+“933;”+model.ImageFile.FileName;字符串filePath=Path.Combine(ParentFolder,uniqueFileName);model.ImageFile.CopyTo(新文件流(filePath,FileMode.Create));ImageGallery=新建ImageGallery