tags:

views:

194

answers:

1

I have a portion of code like this:

Process proc = null;
try
{
    proc = new Process();
    string dir = HttpContext.Current.Server.MapPath("~/Other/");
    proc.StartInfo.WorkingDirectory = dir;
    p.StartInfo.FileName = "batch.bat";
    p.StartInfo.CreateNoWindow = true;
    p.Start();
    p.WaitForExit();
}
catch (Exception e) { }

It will only work if I replace "dir" with

string.Format(@"C:\AbsolutePathHere")

Why?

edit: The code works in a button click event handler. It doesn't work when it's a scheduled Quartz.NET job. It always works when I have the absolute path. So my question is probably: How do I make Quartz.NET and MapPath play nice?

A: 

What is the value or 'dir' after the call to MapPath? What exception is throwing? It is possible that the worker process does not have permission to execute the batch.bat file.

Without a few more details, its not easy to give you a definitive answer.

Edit Have you considered the fact that Quartz.NET does not have access to a HttpContext.Current and therefore the MapPath will not resolve?

Edit2 Is it possible to use AppDomain.CurrentDomain.BaseDirectory to determine the path that you want instead of the ~ (tilda) substitution? I've also seen references to System.Web.Hosting.HostingEnvironment.MapPath() which you might try as well.

CodeMonkeyKing
System.Web.Hosting.HostingEnvironment.MapPath() worked great - thank you