?
Solved

How to get the relative Path from absolute Path.

Posted on 2014-01-02
6
Medium Priority
?
466 Views
Last Modified: 2014-01-06
How to get the relative Path from absolute Path. I am using this in .Net 3.5 application.

I want  \Details\Page1.aspx  from
c:\Projects\NewApplication\NewApplication\Details\Page1.aspx  


Thanks
0
Comment
Question by:KavyaVS
6 Comments
 
LVL 41

Assisted Solution

by:guru_sami
guru_sami earned 200 total points
ID: 39752305
Here's sample code snippet:
var physicalpath= "c:\Projects\NewApplication\NewApplication\Details\Page1.aspx";
Response.Write(physicalpath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"],"/"));

Open in new window

You might also have to replace \ by /
0
 
LVL 7

Assisted Solution

by:Kishan Zunjare
Kishan Zunjare earned 200 total points
ID: 39753314
Hi,

Convert absolute path back into a relative web path :

This migh work;
String RelativePath = AbsolutePath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty);

Open in new window

Thanks
Kishan
0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 39753910
For your requirement, I would like to know what you are trying to do exactly?

It will help us to answer your question as per that.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:KavyaVS
ID: 39757887
I am doing the directory browsing in the .Net application.
If the page URL is c:\Projects\NewApplication\NewApplication\Details\Page1.aspx,
I am trying to get  \Details\Page1.aspx from Page URL.

Thanks
0
 
LVL 16

Accepted Solution

by:
Vikram Singh Saini earned 1600 total points
ID: 39758540
Hi,

Here is the solution -

static void Main(string[] args)
        {
            const string filePath = @"c:\Projects\NewApplication\NewApplication\Details\Page1.aspx";

            var lastDirectory = Path.GetFileName(Path.GetDirectoryName(filePath));
            var fileName = Path.GetFileName(filePath);

            Console.WriteLine("The path is: " + filePath);

            Console.WriteLine("\nThe file name with last directory is: " + lastDirectory + @"\" + fileName);

            Console.ReadKey();
        }

Open in new window

0
 

Author Closing Comment

by:KavyaVS
ID: 39760713
Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question