Alen Šimunic
Alen Šimunic

Reputation: 553

C# PrivateFontCollection AddFontFile from relative path

I have OpenSans-Light.ttf in the this folder from root: ~/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"

How do I target that font file?

Upvotes: 0

Views: 518

Answers (1)

Alen Šimunic
Alen Šimunic

Reputation: 553

I have found a solution using MapPath:

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

Upvotes: 0

Related Questions