Blog

System.Uri class for getting the relative path

Posted by Shinuraj Blogs | Files, Directory, IO Feb 15, 2011
How to find a relative path based on a base path.

Suppose if we need to find a relative path based on a base path, we can use uri class in system.uri  namespace as shown below. 

           
Uri
baseUri = new Uri(basePath);
            Uri fullUri = new Uri(fullPath);
            Uri relativeUri = baseUri.MakeRelativeUri(fullUri);
For example if you are working in a folder called C:\Windows\templates\ and I want to find a relative path for C:\Windows\templates\subdir\test.txt
I want to receive back subdir\test.txt. - In other words always return a non-hardcoded path based on some other known directory.
post comment
     
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter