簡體   English   中英

C#PrivateFontCollection AddFontFile來自相對路徑

[英]C# PrivateFontCollection AddFontFile from relative path

我在root文件夾中有OpenSans-Light.ttf:〜/ fonts / open-sans / OpenSans-Light.ttf

PrivateFontCollection privateFontCollection = new PrivateFontCollection();
privateFontCollection.AddFontFile("~/fonts/open-sans/OpenSans-Light.ttf");

但我得到“System.IO.FileNotFoundException:找不到文件”

如何定位該字體文件?

我找到了一個使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM