Get license file from folder in C # project

I have a license file that I need to get at runtime in order to create pdf files. After I created the PDF file in memory, I need to call the method on this pdf to install the license, for example:

pdf.SetLicense("pathToLicenseFileHere");

The license file is in the same project as the .cs file, which creates a pdf file, but is in a separate folder. I can't get this simple thing to behave correctly, which makes me a little sad, as it really shouldn't be that hard. :(

I am trying to set the path as follows:

string path = @"\Resources\File.lic";

But that just doesn't work for me.

Edit:

A bit more information. I should mention that this is a web service that returns pdf: s as byte []. The web service creates pdf: s, and during this creation process I need to install a license file in order to remove any watermarks from the pdf document. The pdf file itself is not saved on disk, and it needs to access the license file only after it is created.

0
source share
2 answers

So, the file is in your project, and you need it in the same folder (structure) in your folder where your application is located.

If I'm right, there are two approaches to make this work:

  • Mark the file as Content so that VS will copy it to the folder of your .exe file.
  • , .

1 ( )

Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "license.txt").

, . VS , , . , , .

2 ( )

  • ( ) (Project - )
  • MyProject - Properties - Resources.resx
  • ...

. Properties.Resources.MyFileName. ( ) ( ).

, , , , ( , SQL XML ).

+5

, .cs.

+1

Source: https://habr.com/ru/post/1738817/


All Articles