易截截图软件、单文件、免安装、纯绿色、仅160KB

ASP.NET将Web站点下的绝对路径转换为虚拟路径

ASP.NET将Web站点下的绝对路径转换为虚拟路径
2009-11-25 10:39
很经常使用到的一个功能,但在在网上却一直没有找到相关的解决方法,今天借着项目应用到的机会写了两个将绝对路径转换为虚拟路径封装好的方法
  将Web站点下的绝对路径转换为相对于指定页面的虚拟路径
  /**//// <summary>
  /// 将Web站点下的绝对路径转换为相对于指定页面的虚拟路径
  /// </summary>
  /// <param name="page">当前页面指针,一般为this</param>
  /// <param name="specifiedPath">绝对路径</param>
  /// <returns>虚拟路径, 型如: ../../</returns>
  public static string ConvertSpecifiedPathToRelativePathForPage(Page page, string specifiedPath)
  {
   // 根目录虚拟路径
   string virtualPath = page.Request.ApplicationPath;
   // 根目录绝对路径
   string pathRooted = HostingEnvironment.MapPath(virtualPath);
   // 页面虚拟路径
   string pageVirtualPath = page.Request.Path;
   if (!Path.IsPathRooted(specifiedPath) || specifiedPath.IndexOf(pathRooted) == -1)
   {
   throw new Exception(string.Format("\"{0}\"是虚拟路径而不是绝对路径!", specifiedPath));
   }
   // 转换成相对路径
   //(测试发现,pathRooted 在 VS2005 自带的服务器跟在IIS下根目录或者虚拟目录运行似乎不一样,
   // 有此地方后面会加"\", 有些则不会, 为保险起见判断一下)
   if (pathRooted.Substring(pathRooted.Length - 1, 1) == "\\")
   {
   specifiedPath = specifiedPath.Replace(pathRooted, "/");
   }
   else
   {
   specifiedPath = specifiedPath.Replace(pathRooted, "");
   }
   string relativePath = specifiedPath.Replace("\\", "/");
   string[] pageNodes = pageVirtualPath.Split('/');
   // 减去最后一个页面和前面一个 "" 值
   int pageNodesCount = pageNodes.Length - 2;
   for (int i = 0; i < pageNodesCount; i++)
   {
   relativePath = "/.." + relativePath;
   }
   if (pageNodesCount > 0)
   {
   // 如果存在 ".." , 则把最前面的 "/" 去掉
   relativePath = relativePath.Substring(1, relativePath.Leng


相关文档:

ASP.NET

四、MultiView 类
      MultiView 控件是一组 View 控件的容器。使用它可定义一组 View 控件,其中每个 View 控件都包含子控件。然后,应用程序可根据用户标识、用户首选项以及在查询字符串参数中传递的信息等条件,向客户端呈现特定的 View 控件。也可以使用 MultiView 控件创建向导。这种情况 ......

ASP.NET


      RadioButton 控件和 RadioButtonList 控件使用户能够从一小组互相排斥的预定义选项中进行选择。
 
一、功能
可以使用 CheckBox 控件和 CheckBoxList 控件执行以下操作:
·当选中某个单选按钮时引起页回发。
·当用户选中某个单选按钮时捕获用户交互。
&middo ......

ASP.NET


您可以使用 Substitution 控件,在网页上创建可动态更新并可随后集成到缓存页中的区域。
 
一、方案
使用 Substitution 控件可以在要缓存输出的网页上指定要显示动态内容的部分。对于多数内容都要进行缓存的页,Substitution 控件提供了进行部分页缓存的简化的解决方案。您可以缓存整个页的输出,然后使用 Subst ......

asp.net 对XML 读写查操作

  首先看下XML结构
<?xml version="1.0" encoding="utf-8"?>
<corplist>
<corp>
<linkname>陈先生</linkname>
<corpname>XXXXXXXXX公司</corpname>
<email>xxxxx@126.com</email>
</corp>
<corp>
<linknam ......

asp.net中多行文本框高度自适应内容的问题

 在网上搜查了很久,关于asp.net中多行文本框高度自适应内容的解决方法
<td style="width:700px" align=center valign=top>
        <asp:TextBox runat="server" ID="txtContent" Width=100% ReadOnly=true  Wrap=true TextMode="MultiLine" MaxLength="1073741823" BorderWidt ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号