Thursday 23 May 2013

Image Insert into database using FileUpload control in ASP.NET And retrived


 if (FileUploadLogo.HasFile == true)
                    {
                        //getting length of uploaded file
                        int length = FileUploadLogo.PostedFile.ContentLength;
                        //create a byte array to store the binary image data
                        byte[] imgbyte = new byte[length];
                        //store the currently selected file in memeory
                        HttpPostedFile img = FileUploadLogo.PostedFile;
                        //set the binary data
                        img.InputStream.Read(imgbyte, 0, length);
                        string imagename = FileUploadLogo.FileName;
                        newBrand.BrandLogo = imgbyte;
                        FileUploadLogo.SaveAs(Server.MapPath("~/images/AMS/Inventory/Brand/" + FileUploadLogo.FileName));
                        string FileName = Path.GetFileName(FileUploadLogo.FileName);
                        newBrand.Logo_Name = FileName;
               }

                                                            Retrived

 var brand =( from bra in ERPManagement.GetInstance.GetAllBrand()
                            where bra.Brand_ID == BrandID
                            select bra).ToList();
                TxtBrand.Text = brand[0].Brand_Name;
                TxtDescription.Text = brand[0].Brand_Description;
                ImgLogo.ImageUrl = "~/images/AMS/Inventory/Brand/" + brand[0].Logo_Name;
                ImgLogo.DataBind();
                BrandID = 0;

No comments:

Post a Comment