c# Relative Path convert to Absolute Path

Reference:
http://stackoverflow.com/questions/4796254/relative-path-to-absolute-path-in-c
http://stackoverflow.com/questions/1399008/how-to-convert-a-relative-path-to-an-absolute-path-in-a-windows-application

Relative Path => Absolute Path

  var path = Path.Combine(FolderPath, relative);
  path = Path.GetFullPath(path);

Absolute => Relative Path

   var fileUri = new Uri(strTargetPath);
   var refUri = new Uri(Application.ExecutablePath);
   var strRelative = refUri.MakeRelativeUri(fileUri).ToString();
   strRelative = Uri.UnescapeDataString(strRelative);

You should use Uri.UnescapteDataString to convert special character such as %23 to “#”.
Here is the reference:
http://stackoverflow.com/questions/575440/url-encoding-using-c-sharp

posted on 2016-10-05 12:56  norsd  阅读(460)  评论(0编辑  收藏  举报

导航