StackOverflow user Joe (sorry, no last name) helped me big time by answering my question on Business logic shared by ASP.NET / WinForms: find the location of the assembly to access relative files to it.
Before showing the code at the bottom of this blog post, let me explain the question in more detail:
Basically I was in the midst of refactoring some ‘inherited’ business logic code that – before refactoring – for the ASP.NET side needs to be initialized with an absolute path, but on the WinForms / WPF side only with a relative path to a GetExecutingAssembly directory.
To ease xcopy deployment, I wanted all configuration settings to be relative. But I hadn’t found a common means for these platforms to obtain a directory usable as a root for accessing relative files.
That way I could put identical settings in both the Web.config and App.config, heck even generate them based on a common fragment, whithout having to hard-code absolute path names.
I knew about Assembly.GetExecutingAssembly, but in ASP.NET that location is not where the web site is (both IIS and the WebDevelopment server make use of temporary locations to store the assemblies).
ASP.NET does have Server.MapPath and HostingEnvironment.MapPath, but I didn’t want to make the business logic depend on ASP.NET.
Joe came up with this solution, which works dandy: Read the rest of this entry »
Like this:
Like Loading...