Esempio n. 1
0
    protected void Button1_Click1(object sender, EventArgs e)
    {
        if (DropDownList2.SelectedItem.Text == "Map")
        {
            int    a            = 0;
            string path         = Server.MapPath("");
            string sid          = DropDownList3.SelectedValue.ToString();
            string OriginalName = FileUpload3.FileName.ToString();
            byte[] Filedata     = (byte[])FileUpload3.FileBytes;
            int    count        = Filedata.Length;

            Stream sr = FileUpload3.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 (FileUpload3.HasFile == true && FileUpload3.PostedFile.ContentLength != 0 && img.Height >= 128 && img.Width >= 128)
                {
                    try
                    {
                        if (DropDownList1.SelectedItem.Text == "Historical Spots")
                        {
                            string     lpid = DropDownList3.SelectedValue.ToString();
                            GeneralBAL ph   = new GeneralBAL();
                            a = ph.InsertSpotMap(sid, ("~/image/" + sid + "_Map_" + OriginalName));
                            FileStream fs = new FileStream(path + @"\image\" + sid + "_Map_" + OriginalName, FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Write(Filedata, 0, count);
                            fs.Flush();
                            fs.Close();
                        }
                        if (a != 0)
                        {
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Map Photo Added.');location='GalleryManager.aspx';", true);
                        }
                        else
                        {
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Contact Administrator.');", 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);
            }
        }
    }
Esempio n. 2
0
    protected void Button1_Click1(object sender, EventArgs e)
    {
        if (DropDownList2.SelectedItem.Text == "Map")
        {
            int a = 0;
            string path = Server.MapPath("");
            string sid =DropDownList3.SelectedValue.ToString();
            string OriginalName = FileUpload3.FileName.ToString();
            byte[] Filedata = (byte[])FileUpload3.FileBytes;
            int count = Filedata.Length;

            Stream sr = FileUpload3.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 (FileUpload3.HasFile == true && FileUpload3.PostedFile.ContentLength != 0 && img.Height >= 128 && img.Width >= 128)
                {
                    try
                    {
                        if (DropDownList1.SelectedItem.Text == "Historical Spots")
                        {
                            string lpid = DropDownList3.SelectedValue.ToString();
                            GeneralBAL ph = new GeneralBAL();
                            a = ph.InsertSpotMap(sid, ("~/image/" + sid + "_Map_" + OriginalName));
                            FileStream fs = new FileStream(path + @"\image\" + sid + "_Map_" + OriginalName, FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Write(Filedata, 0, count);
                            fs.Flush();
                            fs.Close();

                        }
                        if (a != 0)
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Map Photo Added.');location='GalleryManager.aspx';", true);
                        else
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Contact Administrator.');", 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);
        }
    }