I recently had to make a dropdownlist populated with fonts. Luckily, .NET allows you to use the installed fonts very easy.

First, add a drowdownlist to your ASP.NET page like this:

<asp:DropDownList runat="Server" id="ddlFonts" />

Then call this method to do the actual databinding of the fonts:

private void BindFonts()
{
   System.Drawing.Text.InstalledFontCollection col = new System.Drawing.Text.InstalledFontCollection();
   foreach (System.Drawing.FontFamily family in col.Families)
   {
      ddlFonts.Items.Add(family.Name);
   }
}

That's all there is to it. Be aware that the fonts are the ones installed on the server hosting your web page.

A couple a months ago, I wrote how to remove whitespace from an ASP.NET page. However, the whitespace removal was to extreme for most websites. It mangled with the HTML to such an extent that only very simple websites could use it without damaging their code.

I’ve just finished a more complex website and therefore had to make some changes to my original whitespace removal method. Otherwise, the JavaScript wouldn’t work including the postbacks.

To make it work, simply paste this method into your .aspx or master page.

protected override void Render(HtmlTextWriter writer)
{
   using (HtmlTextWriter htmlwriter = new HtmlTextWriter(new System.IO.StringWriter()))
   {
      base.Render(htmlwriter);
      string html = htmlwriter.InnerWriter.ToString();

      html = Regex.Replace(html, @"(?<=[^])\t{2,}|(?<=[>])\s{2,3}(?=[<])|(?<=[>])\s{2,3}(?=[<])|(?=[\n])\s{2,3}", String.Empty);
      html = Regex.Replace(html, @"[\f\r\t\v]?([\n\xFE\xFF/{}[\];,<>*%&|^!~?:=])[\f\r\t\v]?", "$1");
      html = html.Replace(";\n", ";");

      writer.Write(html.Trim());
   }
}

I’ve calculated that the total HTML file size will be reduces by 10-13 %. To see an example of this method, just visit www.wulffmorgenthaler.com and view the source.