views:

1496

answers:

5

I'm working with DotNetNuke's scheduler to schedule tasks and I'm looking to get the physical file path of a email template that I created. The problem is that HttpContext is NULL because the scheduled task is on a different thread and there is not http request. How would you go about getting the file's physical path?

A: 

Since this process is really out-of-band in relation to the web site, maybe you can just put the path in a config file.

May not be the best idea, but it is an alternative.

Moose
A: 

what says this.GetType().Assembly.Location ?

Michael
It returns c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\mywebsite\50f1a686\ab5b581d\App_Code.xkcsxvg6.dll
John
A: 

Can you look at the Assembly & the CodeBase paths like this:

Imports System.Reflection
Imports System.IO
...
Path.GetDirectoryName( Assembly.GetExecutingAssembly().CodeBase )

That kind of stuff doesn't always work, so what I would recommend doing is writing a log with a bunch of data about the assembly, to see what works in this location. It is what I had to do to get something similar when I was creating a COM component to be hosted in AppCenter. I used this to "get" what "APP_BASE" should be, and set that, so the app.config file would load properly.

Log.Write ( Assembly.GetExecutingAssembly().CodeBase )
Log.Write ( Assembly.GetExecutingAssembly().Location )
Log.Write ( Path.GetFullPath(".") )
Log.Write ( Application.StartupPath )
... and so on, whatever you can think of ...
Andrew Backer
+3  A: 

System.Web.Hosting.HostingEnvironment.MapPath is what you're looking for. Whenever you're using the Server or HttpContext.Current objects, check first to see if HostingEnvironment has what you need.

bdukes
A: 

There are many ways of doing this, I personally get around it by storing path information as a config option for my modules, it isn't elegant, but it works and works every time.

Joe Brinkman I belive somewhere around has a blog posting on how to construct a new HTTPContext for use inside the scheduler.

Mitchel Sellers