title: Want to display no image in Handler
body: <p>I am trying to show an image in a grid view through a handler.But when there is no path in the DB it shows the dirty no image logo. I need to display a "NOImage" image where there are no image.</p>
  
  <pre><code> &lt;asp:TemplateField HeaderText="Path_Image"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:Image ID="Image1" runat="server" ImageUrl='&lt;%# "LargeImage.ashx?p=" + Eval("Name") + "&amp;q=" + Eval("Vertual_Path") %&gt;' /&gt;
                              &lt;/ItemTemplate&gt;
  &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p>///LargeImage.ashx..</p>
  
  <pre><code>using System;
  using System.Drawing;
  using System.Drawing.Drawing2D;
  using System.Drawing.Imaging;
  using System.IO;
  using System.Text.RegularExpressions;
  using System.Web;
  
  public class LargeImage : IHttpHandler
  {
      private Regex _nameValidationExpression = new Regex(@"[^\w/]");
      private int _thumbnailSize = 250;
  
      public void ProcessRequest(HttpContext context)
      {
          string photoName = context.Request.QueryString["p"];
          string P_Path = context.Request.QueryString["Q"];
          if (photoName == "" )
          {
              //file = (byte[])reader["Image"];
             // FileStream fs = File.OpenRead(HttpContext.Current.Server.MapPath("~/Article/NoImage.png"));
              //File = new byte[fs.Length];
              //fs.Read(File, 0, File.Length);
              context.Server.MapPath("~/Article/NoImage.jpg");
          }
          else
          {
              if (_nameValidationExpression.IsMatch(photoName))
              {
  
                  throw new HttpException(404, "Invalid photo name.");
              }
              string cachePath = Path.Combine(HttpRuntime.CodegenDir, photoName + ".Large.png");
              if (File.Exists(cachePath))
              {
                  OutputCacheResponse(context, File.GetLastWriteTime(cachePath));
                  context.Response.WriteFile(cachePath);
                  return;
              }
              else
              {
  
              }
              //string photoPath = context.Server.MapPath("~/Photo/" + photoName + ".jpg");
              // string photoPath = context.Server.MapPath("~/Photo/" + photoName + ".jpg");
              string photoPath = context.Server.MapPath(P_Path + "\\" + photoName + ".jpg");
  
              Bitmap photo;
              try
              {
                  photo = new Bitmap(photoPath);
              }
              catch (ArgumentException)
              {
  
                  throw new HttpException(404, "Photo not found.");
              }
              context.Response.ContentType = "image/pjpeg";
              int width, height;
  
              if (photo.Width &gt; photo.Height)
              {
                  width = _thumbnailSize;
                  height = photo.Height * _thumbnailSize / photo.Width;
              }
              else
              {
                  width = photo.Width * _thumbnailSize / photo.Height;
                  height = _thumbnailSize;
              }
              Bitmap target = new Bitmap(width, height);
              using (Graphics graphics = Graphics.FromImage(target))
              {
                  graphics.CompositingQuality = CompositingQuality.HighSpeed;
                  graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                  graphics.CompositingMode = CompositingMode.SourceCopy;
                  graphics.DrawImage(photo, 0, 0, width, height);
                  using (MemoryStream memoryStream = new MemoryStream())
                  {
  
                      //context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + photoName  + "\"");
                      context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + DateTime.UtcNow.ToString() + "\"");
                      target.Save(memoryStream, ImageFormat.Jpeg);
                     // OutputCacheResponse(context, File.GetLastWriteTime(photoPath));
                      // OutputCacheResponse(context, File.GetLastWriteTime(photoPath));
                      using (FileStream diskCacheStream = new FileStream(cachePath, FileMode.CreateNew))
                      {
                          memoryStream.WriteTo(diskCacheStream);
                      }
                      memoryStream.WriteTo(context.Response.OutputStream);
                      context.Response.Flush();
                  }
              }
          }
      }
  </code></pre>