Enumerate Themes available

Last post 07-27-2005 4:29 PM by Scott W. 8 replies.

Sort Posts:

  • Hmm [^o)] Enumerate Themes available

    07-26-2005, 4:59 PM
    • Member
      122 point Member
    • Valvert
    • Member since 08-22-2003, 7:34 AM
    • Brussels
    • Posts 25
    Hi,

    I would like to list in a dropdownlist all the themes available for my website.

    Is it possible ?

    Thanks
  • Re: Enumerate Themes available

    07-26-2005, 6:47 PM
    • Member
      650 point Member
    • Scott W
    • Member since 04-12-2003, 8:50 PM
    • Earth
    • Posts 130
    They should all be in the App_Themes folder. Just use the FSO to list the folders under that. When they select the folder name in the dropdownlist, just set the theme equal to that.

    I have some code that I used to do exactly this at home, I'll post it when I get back home this evening.
    Scott Willsey
  • Re: Enumerate Themes available

    07-26-2005, 6:54 PM
    • Star
      8,834 point Star
    • MorningZ
    • Member since 07-22-2002, 2:39 PM
    • Fort Lauderdale, FL
    • Posts 1,815

    oh, its most definitely possible!!

    Just not sure if what i am suggesting is the "proper" way, but it'd work:

    You could use the stuff built into the System.IO namspace to get a list of subdirectories in the "app_theme" directory and fill a list with those

    "If you make it idiot proof, they'll build a better idiot"
  • Re: Enumerate Themes available

    07-26-2005, 8:52 PM
    • Member
      650 point Member
    • Scott W
    • Member since 04-12-2003, 8:50 PM
    • Earth
    • Posts 130
    Assuming a dropdownlist:

    <asp:DropDownList ID="ThemesDropDownList" runat="server">
    </
    asp:DropDownList>

    The following populates it with the name of each folder in the App_Themes folder (you need to reference System.IO):

    protected void Page_Load(object sender, EventArgs e)
    {
       
    if (!Page.IsPostBack)
        {
           
    if (Directory.Exists(Server.MapPath("~/App_Themes")))
            {
               
    string[] subdirs = Directory.GetDirectories(Server.MapPath("~/App_Themes"));
               
    foreach (string dir in subdirs)
                {
                   
    DirectoryInfo dirInfo = new DirectoryInfo(dir);
                    ThemesDropDownList.Items.Add(dirInfo.Name);
                }
            }
        }
    }

    Scott Willsey
  • Re: Enumerate Themes available

    07-26-2005, 9:19 PM
    • Star
      8,834 point Star
    • MorningZ
    • Member since 07-22-2002, 2:39 PM
    • Fort Lauderdale, FL
    • Posts 1,815

    Hang... i was going to comment about the lag on your reply showing up, but i won't, lol 

     

    ooops :)

    "If you make it idiot proof, they'll build a better idiot"
  • Re: Enumerate Themes available

    07-27-2005, 2:47 AM
    • Member
      122 point Member
    • Valvert
    • Member since 08-22-2003, 7:34 AM
    • Brussels
    • Posts 25

    Thank you for this solution of course.

    But I was looking for another one more system oriented. But I guess the Framework does not support this possibility.

  • Re: Enumerate Themes available

    07-27-2005, 6:00 AM
    • Member
      650 point Member
    • Scott W
    • Member since 04-12-2003, 8:50 PM
    • Earth
    • Posts 130
    Well... quite frankly my guess is that if there was some built in theme enumeration in the framework, it would be similar to this. After all, as far as I can tell when you apply a theme, it just goes and looks in App_Themes/NameOfTheme to find it. As far as I can tell it's all FSO which makes sense really.

    It's simple and it works. I think it's okay to augment existing functions with your own where it makes sense. Smile [:)]

    Cheers.
    Scott Willsey
  • Re: Enumerate Themes available

    07-27-2005, 10:35 AM
    • Member
      590 point Member
    • bttrflii
    • Member since 06-28-2005, 8:33 PM
    • Posts 132
    do you also by chance have a nifty way of populating the drop down list's selected value with the current theme?

    for example, i have "theme1", "theme2", and "theme3".  i navigate to my page and a drop down list is populated with the three themes (thanks for the code snippet!).  since i haven't changed the theme yet, theme1 should be selected in the list.  when i choose theme3, the theme changes, but now theme3 should be selected in the list (and isn't).

    notes:
    - i have "theme1" set as default in web.config
    - i'm currently using session["theme"] to allow changing of themes
    - currently, the theme is changing for the whole site and the list is populating like it should.  i'm just missing this one part for usability.

    thanks!
    ~ cj
  • Re: Enumerate Themes available

    07-27-2005, 4:29 PM
    • Member
      650 point Member
    • Scott W
    • Member since 04-12-2003, 8:50 PM
    • Earth
    • Posts 130
    Same way as you select any string value you want selected in any dropdownlist: after you populate the dropdownlist, just select the item with the name matching the current page theme:

    if (Directory.Exists(Server.MapPath("~/App_Themes")))
    {
        
    string[] subdirs = Directory.GetDirectories(Server.MapPath("~/App_Themes"));
        
    foreach (string dir in subdirs)
         {
           
    DirectoryInfo dirInfo = new DirectoryInfo(dir);
            ThemeDropDownList.Items.Add(dirInfo.Name);
            ThemeDropDownList.SelectedIndex =ThemeDropDownList.Items.IndexOf(ThemeDropDownList.Items.FindByText(
    Page.Theme));
         }
    }

    Scott Willsey
Page 1 of 1 (9 items)