I'm using C# to get the exact path of the system's fonts folder. Couldn't find which class/dll does it.开发者_高级运维
string fontsfolder = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Fonts);
Note that the Fonts folder in the SpecialFolder enumeration is only available in .Net 4 and beyond.
For the answers here that specify Environment.SpecialFolders.Fonts
, that enumeration value only exists in .NET 4.0+.
For .NET 1.1 - 3.5 you can do the following:
The Fonts folder is inside the Windows folder (e.g. C:\Windows\Fonts). Programmatically grab it through these steps:
Key off a different special folder that does exist in the enumeration value of .NET 2, like the system folder
Environment.SpecialFolder.System
.Grab the parent folder of the system folder (gets the base Windows folder)
Concatenate the Fonts name onto the Windows folder to get the final result.
This code sample uses the System folder and does it. There are other folders you can key off.
using System.IO;
// get parent of System folder to have Windows folder
DirectoryInfo dirWindowsFolder = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.System));
// Concatenate Fonts folder onto Windows folder.
string strFontsFolder = Path.Combine(dirWindowsFolder.FullName, "Fonts");
// Results in full path e.g. "C:\Windows\Fonts"
string fontFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);
Environment.SpecialFolders.Fonts
精彩评论