I have an asp.net web api solution with different project:
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.