Server & Trace in a Helper Class?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

How can I access Server and Trace within a helper class?

I have a webform that allows user to select a PDF file (on the web server)
and render a jpeg image of that PDF file. The helper class has a method like
this:

public void ProcessFile(string virtualPath, string outputFilename)
{
Doc theDoc = new Doc();
theDoc.Read(Server.Mappath(virtualPath));
Trace.Write("The virtual path is: ", virtualPath);
theDoc.Rendering.Save(AppDomain.CurrentDomain.BaseDirectory + "image/" +
outputFilename);
}

The problem I have is I'm not sure how I can access Server and Trace within
the helper class.

I tried to replace Server.Mappath with HttpContext.Current.Server.MapPath
but that gave an error on Current too.

Any suggestions?


Thanks,
WB.
 
You could pass in the current HttpContext as a parameter.

But I suspect you have something else wrong, as HttpContext.Current
should always work if the thread your code is running on is handling an
ASP.NET request.

An even better design might be to do the Server.MapPath() call in the
calling code, and just pass in the full path to ProcessFile, so your
helper class does not have to be unnecessarily tied to the ASP.NET runtime.

Joshua Flanagan
http://flimflan.com/blog
 
Thanks for the advice.

I'm now using System.Web.HttpContext.Current.Server.MapPath() and it's
working fine.
 
Back
Top