示例#1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        int    a            = 0;
        string path         = Server.MapPath("");
        string OriginalName = FileUpload1.FileName.ToString();

        byte[] Filedata = (byte[])FileUpload1.FileBytes;
        int    count    = Filedata.Length;

        Stream sr = FileUpload1.PostedFile.InputStream;

        sr.InitializeLifetimeService();
        sr.Read(Filedata, 0, count);

        if (System.IO.Path.GetExtension(OriginalName).ToLower() == ".jpg")
        {
            System.Drawing.Image img;
            img = System.Drawing.Image.FromStream(sr);
            if (FileUpload1.HasFile == true && FileUpload1.PostedFile.ContentLength != 0 && img.Height >= 128 && img.Width >= 128)
            {
                try
                {
                    if (DropDownList1.SelectedItem.Text == "Home")
                    {
                        if (DropDownList2.SelectedItem.Text == "Banner")
                        {
                            GeneralBAL ph = new GeneralBAL();
                            a = ph.InsertBanner("home", txtDescription1.Text);
                            FileStream fs = new FileStream(path + @"\image\home_banner.jpg", FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Write(Filedata, 0, count);
                            fs.Flush();
                            fs.Close();
                        }
                    }
                    else if (DropDownList1.SelectedItem.Text == "Historical Spots")
                    {
                        if (DropDownList2.SelectedItem.Text == "Banner")
                        {
                            GeneralBAL ph = new GeneralBAL();
                            a = ph.InsertBanner("hs", txtDescription1.Text);
                            FileStream fs = new FileStream(path + @"\image\hs_banner.jpg", FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Write(Filedata, 0, count);
                            fs.Flush();
                            fs.Close();
                        }
                    }
                    else if (DropDownList1.SelectedItem.Text == "LP")
                    {
                        if (DropDownList2.SelectedItem.Text == "Banner")
                        {
                            GeneralBAL ph = new GeneralBAL();
                            a = ph.InsertBanner("lp", txtDescription1.Text);
                            FileStream fs = new FileStream(path + @"\image\lp_banner.jpg", FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Write(Filedata, 0, count);
                            fs.Flush();
                            fs.Close();
                        }
                    }
                    else if (DropDownList1.SelectedItem.Text == "Festivals")
                    {
                        if (DropDownList2.SelectedItem.Text == "Banner")
                        {
                            GeneralBAL ph = new GeneralBAL();
                            a = ph.InsertBanner("fs", txtDescription1.Text);
                            FileStream fs = new FileStream(path + @"\image\fs_banner.jpg", FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Write(Filedata, 0, count);
                            fs.Flush();
                            fs.Close();
                        }
                    }

                    if (a != 0)
                    {
                        Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Photo Added.');location='GalleryManager.aspx';", true);
                    }
                    else
                    {
                        Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Contact Administrator.');location='GalleryManager.aspx';", true);
                    }
                }
                catch
                {
                    Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Some problem occured while adding the photo. Please contact administrator');location='GalleryManager.aspx';", true);
                }
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Please choose correct size and type photo .');location='GalleryManager.aspx';", true);
            }
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Please choose correct size and type photo .');location='GalleryManager.aspx';", true);
        }
    }
示例#2
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        int a = 0;
        string path = Server.MapPath("");
        string OriginalName = FileUpload1.FileName.ToString();
        byte[] Filedata = (byte[])FileUpload1.FileBytes;
        int count = Filedata.Length;

        Stream sr = FileUpload1.PostedFile.InputStream;
        sr.InitializeLifetimeService();
        sr.Read(Filedata, 0, count);

        if (System.IO.Path.GetExtension(OriginalName).ToLower() == ".jpg")
        {
            System.Drawing.Image img;
            img = System.Drawing.Image.FromStream(sr);
            if (FileUpload1.HasFile == true && FileUpload1.PostedFile.ContentLength != 0 && img.Height >= 128 && img.Width >= 128)
            {
                try
                {
                    if (DropDownList1.SelectedItem.Text == "Home")
                    {
                        if (DropDownList2.SelectedItem.Text == "Banner")
                        {
                            GeneralBAL ph = new GeneralBAL();
                            a = ph.InsertBanner("home", txtDescription1.Text);
                            FileStream fs = new FileStream(path + @"\image\home_banner.jpg", FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Write(Filedata, 0, count);
                            fs.Flush();
                            fs.Close();
                        }
                    }
                    else if (DropDownList1.SelectedItem.Text == "Historical Spots")
                    {
                        if (DropDownList2.SelectedItem.Text == "Banner")
                        {
                            GeneralBAL ph = new GeneralBAL();
                            a = ph.InsertBanner("hs", txtDescription1.Text);
                            FileStream fs = new FileStream(path + @"\image\hs_banner.jpg", FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Write(Filedata, 0, count);
                            fs.Flush();
                            fs.Close();
                        }
                    }
                    else if (DropDownList1.SelectedItem.Text == "LP")
                    {
                        if (DropDownList2.SelectedItem.Text == "Banner")
                        {
                            GeneralBAL ph = new GeneralBAL();
                            a = ph.InsertBanner("lp", txtDescription1.Text);
                            FileStream fs = new FileStream(path + @"\image\lp_banner.jpg", FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Write(Filedata, 0, count);
                            fs.Flush();
                            fs.Close();
                        }
                    }
                    else if (DropDownList1.SelectedItem.Text == "Festivals")
                    {
                        if (DropDownList2.SelectedItem.Text == "Banner")
                        {
                            GeneralBAL ph = new GeneralBAL();
                            a = ph.InsertBanner("fs", txtDescription1.Text);
                            FileStream fs = new FileStream(path + @"\image\fs_banner.jpg", FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Write(Filedata, 0, count);
                            fs.Flush();
                            fs.Close();
                        }
                    }

                    if (a != 0)
                        Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Photo Added.');location='GalleryManager.aspx';", true);
                    else
                        Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Contact Administrator.');location='GalleryManager.aspx';", true);
                }
                catch
                {
                    Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Some problem occured while adding the photo. Please contact administrator');location='GalleryManager.aspx';", true);
                }
            }
            else
                Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Please choose correct size and type photo .');location='GalleryManager.aspx';", true);
        }
        else
            Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Please choose correct size and type photo .');location='GalleryManager.aspx';", true);
    }