[英]C# PrivateFontCollection AddFontFile from relative path
I have OpenSans-Light.ttf in the this folder from root: ~/fonts/open-sans/OpenSans-Light.ttf 我在root文件夹中有OpenSans-Light.ttf:〜/ fonts / open-sans / OpenSans-Light.ttf
PrivateFontCollection privateFontCollection = new PrivateFontCollection();
privateFontCollection.AddFontFile("~/fonts/open-sans/OpenSans-Light.ttf");
but I get "System.IO.FileNotFoundException: File not found" 但我得到“System.IO.FileNotFoundException:找不到文件”
How do I target that font file? 如何定位该字体文件?
I have found a solution using MapPath: 我找到了一个使用MapPath的解决方案:
PrivateFontCollection privateFontCollection = new PrivateFontCollection();
privateFontCollection.AddFontFile(HttpContext.Current.Server.MapPath("~/fonts/open-sans/OpenSans-Light.ttf"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.