3

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);
}
janw
  • 8,758
  • 11
  • 40
  • 62
Thando Zulu
  • 33
  • 1
  • 4
  • 7
    You've got `\..resources` in your path. Is that a typo or the problem? – gunr2171 Aug 06 '20 at 13:45
  • 3
    @gunr2171 - it is the tyblem, a typo that grew into a problem :) – Rand Random Aug 06 '20 at 13:55
  • 2
    Note that `Assembly.GetExecutingAssembly().Location` returns the path of the executable, including the executable file name. Plus, you cannot use the Project's `Resources` folder in your application, that folder is used by Visual Studio to store a copy of embedded resources: it won't exist when you deploy. Use the Image as an Embedded object or add the object to a Folder you created in the Project's structure and configure it to `Copy to Output Directory -> Copy if newer`. `Output Directory` will be `\Bin\Debug` or `\Bin\Release`, depending on the active configuration profile. – Jimi Aug 06 '20 at 14:02
  • Does this answer your question? ["Could not find a part of the path" error message](https://stackoverflow.com/questions/21796687/could-not-find-a-part-of-the-path-error-message) – dimitar.bogdanov Aug 06 '20 at 14:04

1 Answers1

3

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!

dimitar.bogdanov
  • 387
  • 2
  • 10