title: How to get URL path in C#
body: <p>I want to get the all the path of URL except the current page of url, eg: my URL is <a href="http://www.MyIpAddress.com/red/green/default.aspx">http://www.MyIpAddress.com/red/green/default.aspx</a> I want to get "<a href="http://www.MyIpAddress.com/red/green/">http://www.MyIpAddress.com/red/green/</a>" only. How can I get.I'm doing like </p>
  
  <pre><code>string sPath = new Uri(HttpContext.Current.Request.Url.AbsoluteUri).OriginalString; System.Web.HttpContext.Current.Request.Url.AbsolutePath;
              sPath = sPath.Replace("http://", "");
              System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
              string sRet = oInfo.Name;
              Response.Write(sPath.Replace(sRet, ""));
  </code></pre>
  
  <p>Its showing exception on new System.IO.FileInfo(sPath) as sPath contain "localhost/red/green/default.aspx" saying  "The given path's format is not supported."</p>