Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# illegal characters in the path

Tags:

c#

I am getting illegal characters in the path by using the below codes:

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

I tested a few variations:

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

But it is still getting the same illegal error.

Can anyone help me see if my code if wrong?

Thanks.

like image 801
kyusan93 Avatar asked Dec 05 '22 16:12

kyusan93


1 Answers

I suggest using the appropriate way to join paths in .net: Path.Combine

So

Path.Combine(Application.StartupPath, "CodesLocation","Template.pdf");
like image 64
Lyndon White Avatar answered Dec 10 '22 09:12

Lyndon White