我想以编程方式检索所有主题名称。
答案 0 :(得分:1)
这是代码。它应该会帮助你。
string dirPath = Server.MapPath( HttpRuntime.AspClientScriptVirtualPath + @"/App_Themes");
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(dirPath);
List<string> result = new List<string>();
if (di.Exists)
{
foreach (System.IO.DirectoryInfo dir in di.GetDirectories())
{
list.Add(dir.Name);
}
}
return result;
答案 1 :(得分:1)
public static string[] GetThemes() {
if (HttpContext.Current.Cache["SiteThemes"] != null) {
return (string[])HttpContext.Current.Cache["SiteThemes"];
} else {
string themesDirPath = HttpContext.Current.Server.MapPath("~/App_Themes");
string[] themes = Directory.GetDirectories(themesDirPath);
for (int i = 0; i <= themes.Length - 1; i++) {
themes[i] = Path.GetFileName(themes[i]);
}
// cache the array
CacheDependency dep = new CacheDependency(themesDirPath);
HttpContext.Current.Cache.Insert("SiteThemes", themes, dep);
return themes;
}
}