简体   繁体   中英

How to access files found in a different project?

I have an asp.net web api solution with different project:

  • MyProject.Web -- This has the web api controllers
  • MyProject.BusinessLogic -- This project holds the business logic and has a folder with.txt files

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/..."

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"

You can use Server.MapPath for this. For example

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

Server.MapPath returns the physical file path that corresponds to the specified virtual path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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