admin管理员组

文章数量:1391977

I have an ASP.NET (.NET 4.7) application and I want to load a static file that's included in my project.

The problem is the project is a child of the main web project. I can't find a way of actually finding the right path. The file is marked as content and copy to output directory and I can see it in the bin folder of the parent project.

This child project doesn't reference any MVC stuff so I don't have access to HttpContext.

My failed attempts so far:

  • Assembly.GetExecutingAssembly().Location - returns Temp folder that only contains dll / pdb files for my child project (and a random .ini file)
  • AppDomain.CurrentDomain.BaseDirectory - returns the root of the parent project's folder (not the bin, but the location of the .csproj)
  • Environment.CurrentDirectory - returns the IIS Express folder
  • The path "." references the IIS Express folder

This seems such a basic thing - I must be missing something obvious!

本文标签: cHow can I load a content file from a child project in an ASPNET applicationStack Overflow