tags:

views:

79

answers:

1

Is there a neat programmatic way to determine which Themes are installed in an ASP.NET application?

I have several ASP.NET applications that use a cookie with the name of "Theme" to set the theme in the Page PreInit event. The trouble is, when using localhost in my development environment, the theme name for one application gets presented to another application and thereby throws the exception:

Theme 'XYZ' cannot be found in the application or global theme directories.

I thought I might be able to just check which themes my application has first to see if what I'm about to set is valid - that is without looking at the content of the App_Themes folder.

+2  A: 

I don't think there is a way to do this without looking at the App_Themes folder.

But you can easily list the existing themes, using something like this:

DirectoryInfo themes = new DirectoryInfo(Server.MapPath("~/App_Themes"));
foreach (DirectoryInfo theme in themes.GetDirectories())
{
    string themeName = theme.Name;
}

Or to check if a given theme exists:

Directory.Exists(Server.MapPath("~/App_Themes/" + theTheme))
M4N
The second one does the trick nicely, thanks.
Moose Factory