Agnostic app Path Mapping for ASPNET and Winforms?

  • Thread starter Thread starter NonNB
  • Start date Start date
N

NonNB

Hi

We have a utility assembly which can be used by both ASPNET and
WinForm apps.
The utility needs to retrieve XML files from a path relative to the
respective installations
(i.e. C:\Program Files\SomeApp\Data\.. and WebApp\App_Data\... for
ASPNET)

Does someone have some some standard code to detect and map the
respective paths in an agnostic manner?

Something like

// Pseudo Code
if (AppDomain.CurrentDomain.IsASPNET())
{
// Called from Web Page
return HttpContext.Current.Server.MapPath(fileName);
}
else
{
// Called from Web Page
return Path.GetDirectoryName
(Assembly.GetExecutingAssembly().Location) + fileName;
}

Thanks in advance!

Stuart
 
NonNB said:
// Pseudo Code
if (AppDomain.CurrentDomain.IsASPNET())
{
// Called from Web Page
return HttpContext.Current.Server.MapPath(fileName);
}
else
{
// Called from WinForm
return Path.GetDirectoryName
(Assembly.GetExecutingAssembly().Location) + fileName;
}

I believe that most of your pseudo-code would actually be usable as real
code. The only thing that I think doesn't exist in reality is the
"AppDomain.CurrentDomain.IsASPNET()" part. But you can easily replace it
with "if (HttpContext.Current!=null)".
 
Back
Top