Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 30th, 2009, 06:35 PM
Authorized User
 
Join Date: Jul 2009
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Global Theme directory?

Hello Imar,

Is there a way to programmatically get all the Themes of a site? (I looked in the forum for this but I could not find it.)

For example I added a third theme called "Brown". I then added it to the dropDown ran the app and selected brown in the dropDown which created the cookie with my preferred theme. Then I closed the app deleted "Brown" from the dropDown and deleted the theme. So basically I decided to discontinue this theme. I still have brown in my preferredTheme cookie so I get an exception that says: Theme 'Brown' cannot be found in the application or global theme directories. Is the "global theme directories collection" a collection I can get to? (I can't find it anywhere.) The only way I can do it is via a string array and if it is not in the collection set it to the Page.Theme and I'm sure there is a better way. In the stack trace there was:System.Web.UI.Page.InitializeThemes() I thought I could put my code there and just do a try catch if failed then set it to Page.Theme, but I can't get to it.

I'm not sure where execution goes after this point:
Code:
private void Page_PreInit(object sender, EventArgs e)
  {
    HttpCookie preferredTheme = Request.Cookies.Get("PreferredTheme");
    if (preferredTheme != null)
    {
      Page.Theme = preferredTheme.Value;
    }
  }// Fails after leaving here

Thanks Imar
Reply With Quote
  #2 (permalink)  
Old July 31st, 2009, 03:57 AM
Imar's Avatar
Wrox Author
Points: 66,797, Level: 100
Points: 66,797, Level: 100 Points: 66,797, Level: 100 Points: 66,797, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,155
Thanks: 65
Thanked 1,392 Times in 1,372 Posts
Default

Hi there,

AFAIK, you can'ty do this programmatically using an API. However, you can loop through the App_Themes folder and get the names from there:
Code:
string rootPath = Server.MapPath("~/App_Themes");
var themesFolders = System.IO.Directory.GetDirectories(rootPath);
foreach (string themeFolder in themesFolders)
{
  string theme = new System.IO.DirectoryInfo(themeFolder).Name;
  Label1.Text += string.Format("{0}<br />", theme);
}
Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old July 31st, 2009, 05:17 PM
Authorized User
 
Join Date: Jul 2009
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Perfect! Thank you. You should see my sln it's a mess.

I wish the Forum for the book was organized by chapter, It would help me find things quicker as well as reduce the same questions you probably get over and over. I notice many people start the the thread with the chapter I'll do that from now on.

Thanks again
Reply With Quote
  #4 (permalink)  
Old August 1st, 2009, 02:58 AM
Imar's Avatar
Wrox Author
Points: 66,797, Level: 100
Points: 66,797, Level: 100 Points: 66,797, Level: 100 Points: 66,797, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,155
Thanks: 65
Thanked 1,392 Times in 1,372 Posts
Default

Quote:
I notice many people start the the thread with the chapter I'll do that from now on.
Excellent idea, especially if you include the page number as well. That makes it easy for everyone to find relevant topics and easy for me to see what the question is about exactly.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to declare the global variable in global.asax? calyn_gately ASP.NET 3.5 Basics 0 August 6th, 2008 08:06 PM
Exception of get theme JasonF430 ASP.NET 2.0 Basics 0 April 16th, 2008 01:31 AM
Theme Selector wont pick up other theme Tawanda BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 May 4th, 2007 08:44 AM
theme selector rav BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 February 11th, 2007 11:44 PM
page theme zhugeliang ASP.NET 2.0 Basics 1 January 9th, 2007 01:40 AM



All times are GMT -4. The time now is 07:18 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.