Need to get a list of available fonts for your application?, this little gem will retrieve the font names of all installed fonts on your server (asp.net) and use them to populate a DropDownList.
These are the namesspaces you need to import to get this running.
[codesyntax lang=”csharp”]
using System.Drawing; using System.Drawing.Text;
[/codesyntax]
Assuming your DropDownList has an ID of “ddl”
[codesyntax lang=”csharp”]
<asp:DropDownList ID="ddl" runat="server" />
[/codesyntax]
Your codebehind just needs an installed font collection object created with a foreach loop to go through in your Page_Load event.
[codesyntax lang=”csharp”]
InstalledFontCollection fonts = new InstalledFontCollection(); foreach (FontFamily family in fonts.Families) { ddl.Items.Add(family.Name); }
[/codesyntax]