Convert Path To Relative Path - CSharp System

CSharp examples for System:String Convert

Description

Convert Path To Relative Path

Demo Code


using System.Globalization;
using System.Windows.Forms;
using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from  ww  w  .  jav a  2 s .  c o m*/

public class Main{
        public static string ConvertPathToRelativePath(string aPath, string aRelativeFolder)
        {
            int dataTagIndex = aPath.IndexOf(aRelativeFolder);
            if (dataTagIndex <= 0) return "";
            string convertedPath = aPath;
            convertedPath = aPath.Substring(dataTagIndex);
            convertedPath = convertedPath.Replace(aRelativeFolder, "");
            convertedPath = convertedPath.Replace("\\", "/");
            return convertedPath;
        }
}

Related Tutorials