Solved

How to get the relative Path from absolute Path.

Posted on 2014-01-02
6
427 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 50 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 50 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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 400 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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 video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now