System.Uri class for getting the relative path

By Shinuraj 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. 

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.

I'm Shinuraj A R, Completed my B-tech in ECE from Govt College of engineering Kannur.Currently working as a senior software engineer @ Cognizant Technology Solution Kochi