0

I stuck with one small thing but very confusing/tricky one. I am trying to access the file "fontawesome-webfont.ttf" in one of my C# file "Example.cs".

var GenderIcons = BaseFont.CreateFont("D:\\code\\Source\\Project\\Content\\fonts\\fontawesome\\" + "fontawesome-webfont.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

I would like to access the file using dynamic path, (..\sample.txt)

Implementation file:

D:\code\Source\Project\Extensions\Export\Example.cs

Dependency file:

D:\code\Source\Project\Content\fonts\fontawesome\" + "fontawesome-webfont.ttf"

In Example.cs, I need to go back to the folder "Project" from there I need to traverse to the fontawesome folder.

How can I change the static path to dynamic?

var GenderIcons = BaseFont.CreateFont("..\\..\\..\\Content\\fonts\\fontawesome\\" + "fontawesome-webfont.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

I am getting the following error.

Message: "..\\..\\..\\Content\\fonts\\fontawesome\\fontawesome-webfont.ttf not found as file or resource."

Any suggestions would be helpful to me.

P.S: Any useful article related to C# file handling is also appreciated

Jeya Suriya Muthumari
  • 1,947
  • 3
  • 25
  • 47
  • 2
    you mean absolute vs relative path instead of static vs dynamic path? [maybe take a look at this here](https://stackoverflow.com/questions/3259583/how-to-get-files-in-a-relative-path-in-c-sharp/3259651) – Matthias Burger Aug 31 '18 at 05:42
  • Generally, it does not matter where example.cs file is. More important: where is executable that runs that code and what values of environment variables are – Chizh Aug 31 '18 at 05:46
  • 1
    Use the debugger and check the current directory while the application is running, because it is the starting point for the relative path. – Sir Rufo Aug 31 '18 at 05:46
  • 1
    Maybe you find it convenient to add the font as embedded resource, and load it as an embedded file (example [here](https://stackoverflow.com/a/8795451/598599) ) – AutomatedChaos Aug 31 '18 at 05:51
  • Just add this file in solution and copy to output directory. Like `copy if newer` option in file property. And use this file name as just `fontawesome-webfont.ttf`. – Prem Aug 31 '18 at 07:28

0 Answers0