RealSimpleBlog custom control (V0.1): Style sets and Integration

.NET, ASP.NET 2.0, Technical stuff, Website
See comments
I didn't write for some time about my RealSimpleBlog control because I was quite busy with other subjects (WPF mostly). However, I am making nice progresses, and I think I can say without too many risks that the integration in my PhotoAlbum will be ready before we fly to Malaysia on wednesday.
Actually, I also integrated the control on my main page, and if you select this link, you will see it in action! I also set the page up to generate a static HTML file on demand, so the old address is still valid!
Yes, it means that I am currently typing this as an XML file, which is really much faster!
In the last few days, here is what I did for the RealSimpleBlog:
  • I integrated the control in my PhotoAlbum on localhost first. The control has been well planned, it seems, because the integration was amazingly easy.
  • After a few tries, I found a good way to generate the static HTML files. It's actually quite easy. I use a query string to "order" the static file from the ASPX file. The only problem is that when you use an external HtmlTextWriter to render the page to a static HTML file, you cannot render the same controls to the Response, not in the same Request. So if I render to the static HTML page, I send back a simple response to the browser, with a link sending back to the normal ASPX page.
  • I added a mechanism allowing to switch very easily between stylesets (a styleset, for me, is a CSS file containing matching styles for all the elements of a HTML page (or pages). For the moment, I have two stylesets: Brown and Purple. In the beginning, I used to call this a skin, but in ASP.NET, the word skin has another meaning: It includes styles, but also controls definitions, etc... This is why I use a different word. I will post more about this after the holidays, but basically I use embedded resources which I extract on demand when the Request arrives. With ASP.NET 1.1, I was embedding the CSS, JavaScript and image files into the RESX file using the application Resourcer. It was quite cumbersome. The new way is much better: Add a folder to the solution, copy the files which you want to embed in this folder, and set the file's "Build action" (in the properties) to "Embedded resource".
Embedding CSS files in a Custom Control DLL
To extract the embedded resources, I use the following code:
Stream oStream
  = oAssembly.GetManifestResourceStream( strPathInResource );"
// with strPathInResource =
// "layout\\realsimpleblog.brown.css"
This provides me with a Stream that I can use to write to a text file if needed. CodeProject has an article about this way to extract embedded resources here.
Note that you can also use the handler Webresource.axd to get the embedded resources without extracting them, as described by Nikhil Kothari.
I published the following features on my website:
  • The code I use to render the page to the static HTML file
  • A page showing the two embedded stylesets, and how easy it is to switch from one to the other.
So, back to work, and very soon V0.1 will be released ;-)
Previous entry | Next blog entry

Comments for RealSimpleBlog custom control (V0.1): Style sets and Integration