I am trying to display some image which are fetching from database using c# asp.net but i am getting some error.
Error:
Server Error in '/' Application.
C:\ASP project\Odiya_Doctor_Client\Odiya_Doctor_Client\ODIYA_Doctor_Admin\Upload\Banner\2015-07-09_01-50-41-PM_Medical-banner-with-icons.jpg
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: C:\ASP project\Odiya_Doctor_Client\Odiya_Doctor_Client\ODIYA_Doctor_Admin\Upload\Banner\2015-07-09_01-50-41-PM_Medical-banner-with-icons.jpg
I am explaining my code below.
index.aspx:
<img runat="server" id="imgCtrl" src='<%# resizeAndConvertToBase64("/ODIYA_Doctor_Admin/Upload/Banner/" + Convert.ToString(Eval("Bnr_Image")),1920,680) %>' class="ls-bg" />
index.aspx.cs:
protected string resizeAndConvertToBase64(string imageDirectory, int newWidth, int newHeight)
{
Bitmap newImage = new Bitmap(newWidth, newHeight);
System.Drawing.Image srcImage = System.Drawing.Image.FromFile(Server.MapPath(imageDirectory));
using (Graphics gr = Graphics.FromImage(newImage))
{
gr.SmoothingMode = SmoothingMode.HighQuality;
gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
gr.DrawImage(srcImage, new Rectangle(0, 0, newWidth, newHeight));
}
MemoryStream ms = new MemoryStream();
newImage.Save(ms, ImageFormat.Gif);
var base64Data = Convert.ToBase64String(ms.ToArray());
return "data:image/gif;base64," + base64Data;
}
Actually i want to access one image which is present inside c:\ASP\ODIYA_Doctor_Admin\Upload\Banner folder but here my inde.aspx page is inside c:\ASP\Odiya_Doctor_Client\Odiya_Doctor_Client folder. In the error message the path is coming C:\ASP project\Odiya_Doctor_Client\Odiya_Doctor_Client\ODIYA_Doctor_Admin\Upload\Banner\2015-07-09_01-50-41-PM_Medical-banner-with-icons.jpg and from this path i want to remove \Odiya_Doctor_Client\Odiya_Doctor_Client. So please help me to resolve this error.
Path.Combine.