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?
For the non working string you should call Server.MapPath(...)
to get the absolute path of your relative string.
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".
精彩评论