Exemplo n.º 1
0
        protected void upload_cmd_Click(object sender, EventArgs e)
        {
            Boolean fileOK = false;

            if (image_upload.HasFile)
            {
                String fileExtension =
                    System.IO.Path.GetExtension(image_upload.FileName).ToLower();
                String[] allowedExtensions = { ".jpg", ".gif", ".png", ".jpeg" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtension == allowedExtensions[i])
                    {
                        fileOK = true;
                        break;
                    }
                }
            }


            try
            {
                if (fileOK)
                {
                    string file_name = image_upload.FileName;

                    //saving original size image
                    string path = Server.MapPath("~/img/OriginalSize_" + file_name);
                    image_upload.PostedFile.SaveAs(path);
                    image_upload.Dispose();


                    //saving display size copy
                    Bitmap target = FixedSize(System.Drawing.Image.FromFile(path), 225, 225) as Bitmap;
                    path = Server.MapPath("~/img/" + file_name);
                    target.Save(path);
                    target.Dispose();
                    int numOfPictures = lg.numOfImages(Session["add_item"].ToString());
                    int isProfile;
                    if (numOfPictures == 0)
                    {
                        isProfile = 1;
                    }
                    else
                    {
                        isProfile = 0;
                    }
                    Imag img = new Imag(Session["add_item"].ToString(), "img/" + file_name, isProfile);
                    lg.addImage(img);
                }
            }
            catch (Exception ex)
            {
            }

            bind();
        }
Exemplo n.º 2
0
 public void addImage(Imag img)
 {
     data = new DB();
     data.addImage(img);
 }