ASP.NET - Accessing copied content
Posted
by James Kolpack
on Stack Overflow
See other posts from Stack Overflow
or by James Kolpack
Published on 2010-04-05T20:02:15Z
Indexed on
2010/04/05
20:13 UTC
Read the original article
Hit count: 241
I have a class library project which contains some content files configured with the "Copy if newer" copy build action. This results in the files being copied to a folder under ...\bin\
for every project in the solution. In this same solution, I've got a ASP.NET web project (which is MVC, by the way). In the library I have a static constructor load the files into data structures accessible by the web project. Previously I've been including the content as an embedded resource. I now need to be able to replace them without recompiling. I want to access the data in three different contexts:
- Unit testing the library assembly
- Debugging the web application
- Hosting the site in IIS
For unit testing, Environment.CurrentDirectory
points to a path containing the copied content. When debugging however, it points to C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE
. I've also looked at Assembly.GetExecutingAssembly().Location
which points to C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\c44f9da4\9238ccc\assembly\dl3\eb4c23b4\9bd39460_f7d4ca01\
. What I need is to the physical location of the webroot \bin
folder, but since I'm in a static constructor in the library project, I don't have access to a Request.PhysicalApplicationPath
.
Is there some other environment variable or structure where I can always find my "Copy if newer" files?
© Stack Overflow or respective owner