Retrieving all the available Fonts from the Windows font folder using System.IO C#

In this blog we are going to see, How to list all the available fonts from Fonts path using System.IO

 

Step 1:            Use namespaces

            System.IO

Step 2:            Fonts Path

                C:\Windows\Fonts

Step 3:            Gets the Special Folder

            Environment.SpecialFolder specialFolder = Environment.SpecialFolder.Fonts;

 

Step 4:            Gets the path of the special folder.

            string path = Environment.GetFolderPath(specialFolder);

 

Step 5:            Creating directory path for fonts path.

            DirectoryInfo directoryInfo = new DirectoryInfo(path);

          

Step 6:            Collect Font file as collection

            FileInfo[] fontFiles = directoryInfo.GetFiles();

 

Step 7:            Displays all the fonts from the path C:\Windows\Fonts

            foreach (var fontFile in fontFiles)

            {

                Response.Write(fontFile.FullName + "<br/>");

            }

 

Step 8:            Path of Fonts

            Response.Write("<b>" + "Fonts" + " :</b> " + path + "<br/>");

 

Output:

C:\Windows\Fonts\VINERITC.TTF
C:\Windows\Fonts\VIVALDII.TTF
C:\Windows\Fonts\VLADIMIR.TTF
C:\Windows\Fonts\vrinda.ttf
C:\Windows\Fonts\vrindab.ttf
C:\Windows\Fonts\webdings.ttf
C:\Windows\Fonts\wingding.ttf
C:\Windows\Fonts\WINGDNG2.TTF
C:\Windows\Fonts\WINGDNG3.TTF


Fonts : C:\Windows\Fonts

 Code Snippet:

                void GetFontsUsingSpecialFolder()

        {

            //Gets the Special Folder

            Environment.SpecialFolder specialFolder = Environment.SpecialFolder.Fonts;

 

            //Gets the path of the special folder.

            string path = Environment.GetFolderPath(specialFolder);

 

            //Creating directory path for fonts path.

            DirectoryInfo directoryInfo = new DirectoryInfo(path);

          

            //Collect Font file as collection

            FileInfo[] fontFiles = directoryInfo.GetFiles();

 

            //Displays all the fonts from the path C:\Windows\Fonts

            foreach (var fontFile in fontFiles)

            {

                Response.Write(fontFile.FullName + "<br/>");

            }

 

            //Path of Fonts

            Response.Write("<b>" + "Fonts" + " :</b> " + path + "<br/>");

        }

 


Thanks for reading this article. Have a nice day.