C # illegal characters in transit

I get illegal characters in transit using the codes below:

string fileNameExisting = Application.StartupPath + "\\CodesLocation\\Template.pdf";
PdfReader templateFile = new PdfReader(fileNameExisting);

I checked a few options:

string fileNameExisting = @Application.StartupPath + "\CodesLocation\Template.pdf";
PdfReader templateFile = new PdfReader(fileNameExisting);

But he still gets the same illegal error.

Can someone help me see if my code is wrong?

Thank.

+3
source share
3 answers

I suggest using a suitable way to combine paths in .net: Path.Combine

So

Path.Combine(Application.StartupPath, "CodesLocation","Template.pdf");
+10
source

An before the string literal disables \escaping (before the variable, it explicitly places the variable as a non-keyword):

Path.Combine(Application.StartupPath, @"CodesLocation\Template.pdf");

And Path.Combine- this is a modern way of concatenating paths (independent of the platform, it will take care of additional reduction).

+2
source

Path.Combine(Application.StartupPath, "CodesLocation\\Template.pdf"). , , Application.StartupPath \.

+2

All Articles