Jaison
Jaison

Reputation: 813

Could not find a part of the path 'D:\~\images\Emblem.JPG'

I am getting the following error while i try to embed a itexsharp logo

Could not find a part of the path 'D:\~\images\Emblem.JPG'.

This is the function which is calling

i have commented the working line and not working line

   private iTextSharp.text.Image CreateAndSetLogo()
          {
              string ImgPath = "D:\\Projects\\Project\\ASPX\\images\\Emblem.JPG"; //Working 

              Not working // string ImgPath = "~/images/Emblem.JPG"; 

              iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(ImgPath);

              logo.ScaleToFit(100, 100);
              logo.SetAbsolutePosition(100f, 680f);
              return logo;
          }

What is the solution?

Upvotes: 2

Views: 2497

Answers (2)

TMN
TMN

Reputation: 3070

I thought using the tilde as a shorthand for the user's home directory was a Unix thing. Are you sure it's supported under Windows? I just tried "cd ~" at a Win7 command prompt and got the error "The system could not find the path specified".

Upvotes: 0

Davide Piras
Davide Piras

Reputation: 44605

For the non working string you should call Server.MapPath(...) to get the absolute path of your relative string.

Upvotes: 4

Related Questions