简体   繁体   English

如何访问在不同项目中找到的文件?

[英]How to access files found in a different project?

I have an asp.net web api solution with different project:我有一个具有不同项目的 asp.net web api 解决方案:

  • MyProject.Web -- This has the web api controllers MyProject.Web -- 这有 web api 控制器
  • MyProject.BusinessLogic -- This project holds the business logic and has a folder with.txt files MyProject.BusinessLogic -- 该项目包含业务逻辑,并有一个包含 .txt 文件的文件夹

Since the.Web project has the controllers and is the main executing project, When I try the below codes, it only returns the path to: "//MyProject.Web/bin/..."由于.Web项目有控制器并且是主要执行项目,当我尝试下面的代码时,它只返回路径:“//MyProject.Web/bin/...”

Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, @"Data\Names.txt")

Is it possible to access the path of files in another project?是否可以访问另一个项目中的文件路径? I do not want to use the full path - eg C:/.../..., But I only need to access it via simple path "ProjectName/folderName/file.txt"我不想使用完整路径 - 例如 C:/.../...,但我只需要通过简单路径“ProjectName/folderName/file.txt”访问它

You can use Server.MapPath for this.您可以为此使用Server.MapPath For example例如

string filePath = Server.MapPath(@"~/Data/Names.txt");

Server.MapPath returns the physical file path that corresponds to the specified virtual path. Server.MapPath返回与指定虚拟路径对应的物理文件路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM