Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find part of the path

Tags:

c#

I've created a billing app that creates a pdf. My issue is the pdf doesn't get created because the header for the pdf isn't being fond, i get a "could not find part of the path c#". I've tried changing the location of the folder and also including it in the bin folder.

var imagepath = @System.Reflection.Assembly.GetExecutingAssembly()
    .Location + @"\..\..resources\pdfHeader.png";
using (FileStream fs = new FileStream(imagepath, FileMode.Open))
{
    var png = Image.GetInstance(System.Drawing.Image.FromStream(fs), ImageFormat.Png);
    png.ScalePercent(25f);
    png.SetAbsolutePosition(pdfDoc.PageSize.Width - 559f - 2f , pdfDoc.PageSize.Height - 2f - 115f);
    pdfDoc.Add(png);
}
like image 839
Thando Zulu Avatar asked Dec 14 '25 14:12

Thando Zulu


1 Answers

The error is pretty self-explanatory, a part of the path is missing (ie. one of the folders in the path doesn't exist). This is most likely caused by this:

 \..\..resources\

You forgot a \ before resources. :)

By the way - please follow naming conventions (here's an official link for C#) for all languages you code in. Your variable should be called imagePath.

Hope I could help!

like image 132
Dimitar Bogdanov Avatar answered Dec 16 '25 04:12

Dimitar Bogdanov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!