public static string GetFullUrlDest(string FolderSrc, string FolderDest, string FullPathSrc) { if (!FullPathSrc.StartsWith(FolderSrc)) { return(""); } string FullPathRest = FullPathSrc.Substring(FolderSrc.Length); if (FullPathRest.StartsWith("/")) { FullPathRest = FullPathRest.Substring(1); } string FullPathDest = CUrl.Combine(FolderDest, FullPathRest); return(FullPathDest); }
/// <summary> /// UrlParent가 '/good/manager/'이고 UrlChild가 '../../images/star.gif'인 경우 /// '/images/star.gif'를 리턴함. /// </summary> /// <param name="UrlParent"></param> /// <param name="UrlChild"></param> /// <returns></returns> public static string ConvertRelativeToAbsolute(string UrlParent, string UrlChild) { if (UrlChild.StartsWith("http://") || UrlChild.StartsWith("ftp://")) { return(UrlChild); } // http://www.site.com은 제거 bool IsError = false; Uri u = null; string Scheme = ""; string Authority = ""; try { u = new Uri(UrlParent, UriKind.Absolute); Scheme = u.Scheme; Authority = u.Authority; } catch (Exception) { IsError = true; } if (!IsError) { UrlParent = u.AbsolutePath; } List <string> aUrlParent = new List <string>(UrlParent.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)); List <string> aUrlChild = new List <string>(UrlChild.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)); //파일은 경로에서 삭제 if (aUrlParent[aUrlParent.Count - 1].IndexOf('.') != -1) { aUrlParent.RemoveAt(aUrlParent.Count - 1); } if (UrlChild.StartsWith("/")) { aUrlParent.Clear(); } else { for (int i = 0; i < aUrlChild.Count; i++) { if (aUrlChild[i] == "..") { aUrlParent.RemoveAt(aUrlParent.Count - 1); aUrlChild.RemoveAt(0); i--; } } } foreach (string UrlChildCur in aUrlChild) { aUrlParent.Add(UrlChildCur); } string UrlNew = string.Join("/", aUrlParent.ToArray()); if (!string.IsNullOrEmpty(Authority)) { UrlNew = CUrl.Combine(Scheme + "//" + Authority, UrlNew); } return(UrlNew); }