Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6594535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:49:28+00:00 2026-05-25T17:49:28+00:00

I have a shared reporting dll that is used in both windows and web.

  • 0

I have a shared reporting dll that is used in both windows and web. I am now trying to move the windows programs to .NET 4 client profile so need to avoid System.Web references.

At some points the code needs to get the directory of the website or the directory of the dll. I used code something like this:

string path;
if (HttpContext.Current != null)
{
    path = HttpContext.Current.Server.MapPath("default.aspx");
}
else
{
    path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}

Is there a way to use reflection or similar to avoid the System.Web reference so I can still get the appropriate path? If so how do I do it?

Any alternatives?

EDIT
The reason I want to do this is I use a reporting system that can take a stylesheet file and apply it to reports (I do this for all reports). As a setting I previously had in the dll itself mystylesheet.repss.So if I wanted to change styles I just change it in the dll and it is applied to all reports. It was then just a case of dropping the appropriate repss file into the root directory on windows and the website. And finding the appropriate path to them.

Trying to use relative paths with the dll results in issues. Passing the report.\mystylesheet.repss works fine in Windows but trying ~/mystylesheet.repss .\mystylesheet.repss or anything else I can think of from the dll in web ends up looking in the wrong directory “c:\windows\system32\inetsrv”.

I could move the setting out to each different windows and web app and pass it in with the full path worked out it seems backwards to do it that way when it is really an internal setting for the dll.

Hope that has all made sense.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:49:28+00:00Added an answer on May 25, 2026 at 5:49 pm

    Why don’t you use paths relative to AppDomain.BaseDirectory.

    This will be the root directory of the web application for ASP.NET, and the directory containing your executable for a Console or WinForms application.

    For other application types, it will generally be a sensible default location: for example, in a VSTO 2005 application, it will be the directory containing the VSTO managed assemblies for your app, not, say, the path to the Excel executable.

    If appropriate, you could support an optional configuration setting (e.g. appSetting) to allow the caller of your DLL to specify an alternate location, while defaulting to the base directory.

    Another option is to allow your callers to specify a path to the stylesheet file, which can be absolute or relative. If relative, make it relative to AppDomain.BaseDirectory.

    if (!Path.IsPathRooted(stylesheetPath))
    {
         stylesheetPath = Path.Combine(
                              AppDomain.CurrentDomain.BaseDirectory, 
                              stylesheetPath);
    }
    ...
    

    Note that if you use a relative path, it will be relative to the current working directory, which can change during the lifetime of an application, and is not the same as the application base directory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're using .NET Remoting with a Client/Shared/Server architecture where: Shared DLL: common to both
I have an ASP.NET web site dedicated to reporting on PBX extension stats. It
In .net we are not allowed to have shared function/methods in abstract classes and
I have created a multi module maven project. Now I have shared the project
For several applications I made for my current client I have shared user accounts.
I have a shared library that I wish to link an executable against using
INTRO I have a TCP/HTTP server that supports plugins in form of Shared Libraries
I have a Reporting services project that has a number of reports in the
Question: I have written a console program that uses the SQL server 2005 web
I have a user reporting that when they use the back button to return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.