Exemplo n.º 1
0
        protected void uploadimage_Click(object sender, EventArgs e)
        {
            string ProductID = Request.QueryString["Id"];
            //check the extension

            string extension = (System.IO.Path.GetExtension(imageFileUploadControl.FileName).ToLower());

            if (extension == ".jpg" || extension == ".jpeg" || extension == ".png" || extension == ".gif")
            {
                System.Drawing.Image img = System.Drawing.Image.FromStream(imageFileUploadControl.PostedFile.InputStream);
                int width  = img.Width;
                int height = img.Height;
                //save the image data
                db_1626504_web1Entities1 db = new db_1626504_web1Entities1();
                Image_Table imageData       = new Image_Table();
                imageData.ImgDescription = AltBox.Text;
                imageData.ImgName        = ProductID;
                imageData.Extension      = extension;
                db.Image_Table.Add(imageData);
                db.SaveChanges();
                //load the image in memory so we can determine it's dimensions


                //note much of the code to do this properly (i.e check file type is correct) is missing
                //get the id from the query string (keeping it as a string is OK in this case)
                //message for user


                string filename = imageData.ImgName.ToString() + extension;
                img.Save(Server.MapPath("~/ProductImages/" + filename));
                litResult.Text = "<p>Your file was uploaded as" + filename + " in the Uploaded Images folder</p>";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string entryIdString        = Request.QueryString["id"];
            int    entryId              = int.Parse(entryIdString);
            db_1626504_web1Entities1 db = new db_1626504_web1Entities1();
            var entry = db.Product_Table.Single(p => p.ProductID == entryId);

            litTitle.Text = entry.ProductDescription;
            var    ProdPrice       = entry.ProductPrice;
            string strproductprice = Convert.ToString(ProdPrice);

            litBody.Text = strproductprice;
            litDate.Text = entry.ProductQuantity;
            var    imgtab    = db.Image_Table.Single(p => p.ImgName == entryIdString);
            string imagefile = imgtab.ImgName;
            string imgextens = imgtab.Extension;
            string alt       = imgtab.ImgDescription;

            string imglocation = imagefile + imgextens;

            Image1.ImageUrl      = "ProductImages/" + imglocation;
            Image1.AlternateText = alt;
        }