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 98081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:07:40+00:00 2026-05-11T00:07:40+00:00

I am building an MVC application in which I am reading a list of

  • 0

I am building an MVC application in which I am reading a list of files from the file system and I want to pass the relative URL to that file to the view, preferably prefixed with ‘~/’ so that whatever view is selected cab render the URL appropriately.

To do this, I need to enumerate the files in the file system and convert their physical paths back to relative URLs. There are a few algorithms I’ve experimented with, but I am concerned about efficiency and minimal string operations. Also, I believe there’s nothing in the .Net Framework that can perform this operation, but is there something in the latest MVC release that can?

  • 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. 2026-05-11T00:07:40+00:00Added an answer on May 11, 2026 at 12:07 am

    At the moment I don’t know any built-in method to do it, but it’s not difficult, I do it like this:

    • We need to get the Application root, and replace it in our new path with ~
    • We need to convert the backslashes to slashes

    public string ReverseMapPath(string path) {     string appPath = HttpContext.Current.Server.MapPath('~');     string res = string.Format('~{0}', path.Replace(appPath, '').Replace('\\', '/'));     return res; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an MVC application which uses Windows Authentication. I want to handle a
Im currently building a controller from my Zend MVC application which would only be
I am building an MVC 3 application which uses the standard Model validation attributes
I'm building a .NET MVC application which will be deployed on a Windows 2003
The MVC application that I am building has a portion of the page (implemented
I am building a web application using ASP.NET MVC that has two very distinct
Hello I'm building a Spring MVC web application that runs on Tomcat 6.0.20 and
I am building an ASP.Net MVC 3 Web application which uses Entity Framework 4.1.
I'm building a MVC application which has a heavy client side scripting using Knockout,JQuery
I'm building a mvc application which will communicate with flash via AMF, anybody knows

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.