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

  • SEARCH
  • Home
  • 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 401323
In Process

The Archive Base Latest Questions

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

If I have a relative path that I need to get from the current

  • 0

If I have a relative path that I need to get from the current server. The following does not work because it is not a valid URI.

var request = WebRequest.Create("\path_to_resource")

I believe that the easiest way would be to put the path in the web.config, however this is easily broken by forgetting to update the config when the application is moved to another server. Is there a better way than?

var request = WebRequest.Create(ConfigurationManager.AppSettings["root"] + "\path_to_resource");
  • 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-12T17:01:25+00:00Added an answer on May 12, 2026 at 5:01 pm

    Well, you can always use something like:

    private string CurrentDomain()
    {
        string currDomain = Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host;
        if (Request.Url.Port != 80 && Request.Url.Port != 443)
            currDomain += (":" + Request.Url.Port);
        return currDomain;
    }
    

    Using these various Request object properties will give you your current domain name onto which you can append your sub-folders for your resource.

    Request.Url.Scheme is the http / https part of the URL, System.Uri.SchemeDelimiter is the :// part, and the Request.Url.Host will be your actual host name (ie. example.com).
    If your site is running on a non-standard port, the calls to Request.Url.Port will add that into the URL “domain name” also.
    Note that this is not bullet-proof code, as it assumes your (for example) running SSL (https) on the default port of 443

    If you need actual physical file paths, you can use Server.MapPath to retrieve the physical file path of the “root” of your ASP.NET application, and append your sub-folders from there.

    See also: ASP.NET Web Site Paths

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

Sidebar

Related Questions

I have a base URL : http://my.server.com/folder/directory/sample And a relative one : ../../other/path How
I have a C# application that includes the following code: string file = relativePath.txt;
How can I have a relative path in the web.config file. This value is
One CSS rule I have learned is that you should use the relative em
In my applications, I often have to use relative paths. For example, when I
I have a question related to how relative paths are interpreted in various environments
I am working on an application where I have an images folder relative to
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have just started using Google Chrome , and noticed in parts of our site,
Have you guys had any experiences (positive or negative) by placing your source code/solution

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.