views:

2749

answers:

3

I have an application where the contents of e-mails that get sent are stored in a .resx file.
This is an ASP.Net application, the .resx file lives in /App_GlobalResources

When I need to send an e-mail, i'm reading this using:

 HttpContext.GetGlobalResourceObject("MailContents", "EmailID").ToString

Now, I need to use the same mailing method from another project (not a website). The mailing method is in a DLL that all the projects in the solution share.

In this other project, I obviously don't have an HttpContext.

How can I read these resources?

My current approach is, inside the Mailing class, check whether HttpContext.Current is null, and if so, use a separate method.
The separate method I'm looking at right now (after resigning myself to the fact that there's nothing better) is to have the path to the .resx file of the website stored in the app.config file, and somehow read that file.
I started trying with System.Resources.ResourceReader, but it looks like it wants a .resources file, not a .resx one.

Any ideas?

A: 

Something is not right with your placement of resources.

Either your resource belongs to the website and should be sent to the mailing method by parameter.

Or, your resource belongs to the mailing API dll and should be kept there (.dll projects can have .resx files too). Then the mailing method should have no problem finding the resource, especcially if you embed it in the dll itself.

Caerbanog
The problem with adding the e-mails to the DLL is that then we need to recompile the DLL to change e-mail contents, which put plainly, sucks.
Daniel Magliola
+1  A: 

I think I answered my own question...
There's a ResXResourceReader class. I couldn't find it because it's in the Windows Forms namespace, which is not included in my current DLL references.

Unfortunately, this will only let me iterate through results, so i'll implement some cute caching (read: memoization) over it...

Daniel Magliola
A: 

The mailing method is in a DLL that all the projects in the solution share.

In this other project, I obviously don't have an HttpContext.

Yes you do. HttpContext is available in any dll called from a website, as long as the class library references System.Web.

martin