Saturday, December 28, 2013

Show an Server Image in Asp.Net

______________________________________________________
  
1st Work
______________________________________________________
  
DirectoryInfo folder = new DirectoryInfo(@"~/CVImage/");
        string files = Label1.Text.Trim();
        string ext = pic_ex.Text.Trim();
        byte[] imageBytes = File.ReadAllBytes(Server.MapPath("~/CVImage/" + files + ext));
        Session["imagename"] = imageBytes;
        
        Image1.ImageUrl = Server.MapPath("~/UI/get_image.aspx");
        Image1.ImageUrl = "~/UI/get_image.aspx?id=";


_________________________________________________________
2nd work
_________________________________________________________

Create a aspx file name get_image.aspx



protected void Page_Load(object sender, EventArgs e)
    {
         
        try
        {
            byte[] image = (byte[])(Session["imagename"]);
            Response.ContentType = "image/JPEG";
            if (image.Length != 0)
                Response.BinaryWrite(image);

           
        }
        catch { }
    }

No comments:

Post a Comment