?
Solved

How to get the relative Path from absolute Path.

Posted on 2014-01-02
6
Medium Priority
?
453 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 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