/// <summary>
/// 遍历路径的模板文件,并存入hashtable中
/// </summary>
/// <param name="directorypath"> 需要遍历扫描的文件夹 </param>
/// <param name="ht"> 返回的模板及配置文件 </param>
/// <returns> 返回包含模板文件及配置文件的hashtable </returns>
private Hashtable GetTemplatesFromPath( string directorypath)
{
Hashtable ht = new Hashtable();
// 指向模板目录
DirectoryInfo dirinfo = new DirectoryInfo(GetMapPath( " templates/ " + directorypath + " / " ));
// 遍历模板目录中的文件
foreach (FileSystemInfo file in dirinfo.GetFileSystemInfos())
{
// 将文件不为空的后缀名为.htm及不以下划线开冰的页页(即排除掉头部包含文件的模块)
if (file != null && (file.Extension.ToLower().Equals( " .html " ) || file.Extension.ToLower().Equals( " .config " )) && file.Name.IndexOf( " _ " ) != 0 )
{
ht[file.Name] = file;
}
}
return ht;
}
///
<summary>
/// 获得当前绝对路径
/// </summary>
/// <param name="strPath"> 指定的路径 </param>
/// <returns> 绝对路径 </returns>
public static string GetMapPath( string strPath)
{
if (HttpContext.Current != null )
{
return HttpContext.Current.Server.MapPath(strPath);
// return strPath;
}
else // 非web程序引用
{
strPath = strPath.Replace( " / " , " \\ " );
if (strPath.StartsWith( " \\ " ))
{
strPath = strPath.Substring(strPath.IndexOf( ' \\ ' , 1 )).TrimStart( ' \\ ' );
}
return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
}
}
/// 获得当前绝对路径
/// </summary>
/// <param name="strPath"> 指定的路径 </param>
/// <returns> 绝对路径 </returns>
public static string GetMapPath( string strPath)
{
if (HttpContext.Current != null )
{
return HttpContext.Current.Server.MapPath(strPath);
// return strPath;
}
else // 非web程序引用
{
strPath = strPath.Replace( " / " , " \\ " );
if (strPath.StartsWith( " \\ " ))
{
strPath = strPath.Substring(strPath.IndexOf( ' \\ ' , 1 )).TrimStart( ' \\ ' );
}
return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
}
}