• Related Post

    Saturday, January 24, 2015

    How To Create Photo Gallery in ASP.NET, C# and SQL Server


    Creating Photo Gallery Code

    public partial class Default3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Label7.Text = Request.QueryString[0].ToString();
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string strImgFileName = "";
            strImgFileName = FileUpload1.FileName.ToString();
            if (strImgFileName != "")
            {
                FileUpload1.SaveAs(MapPath("NewImages") + "\\" + strImgFileName);
                System.Drawing.Image img = System.Drawing.Image.FromFile(MapPath("NewImages") + "\\" + strImgFileName);
                img = img.GetThumbnailImage(130, 100, null, IntPtr.Zero);
                img.Save(MapPath("Thumb") + "\\" + strImgFileName);
                Image1.ImageUrl = "Thumb/" + strImgFileName;
                Label2.Text = strImgFileName;
              //  Session["strImgpath"] = strImgFileName;
            }
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            string strImgFileName = "";
            strImgFileName = FileUpload2.FileName.ToString();
            if (strImgFileName != "")
            {
                FileUpload2.SaveAs(MapPath("NewImages") + "\\" + strImgFileName);
                System.Drawing.Image img = System.Drawing.Image.FromFile(MapPath("NewImages") + "\\" + strImgFileName);
                img = img.GetThumbnailImage(130, 100, null, IntPtr.Zero);
                img.Save(MapPath("Thumb") + "\\" + strImgFileName);
                Image2.ImageUrl = "Thumb/" + strImgFileName;
                Label3.Text = strImgFileName;
                //  Session["strImgpath"] = strImgFileName;
            }
        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            string strImgFileName = "";
            strImgFileName = FileUpload3.FileName.ToString();
            if (strImgFileName != "")
            {
                FileUpload3.SaveAs(MapPath("NewImages") + "\\" + strImgFileName);
                System.Drawing.Image img = System.Drawing.Image.FromFile(MapPath("NewImages") + "\\" + strImgFileName);
                img = img.GetThumbnailImage(130, 100, null, IntPtr.Zero);
                img.Save(MapPath("Thumb") + "\\" + strImgFileName);
                Image3.ImageUrl = "Thumb/" + strImgFileName;
                Label4.Text = strImgFileName;
                //  Session["strImgpath"] = strImgFileName;
            }
        }
        protected void Button4_Click(object sender, EventArgs e)
        {
            string strImgFileName = "";
            strImgFileName = FileUpload4.FileName.ToString();
            if (strImgFileName != "")
            {
                FileUpload4.SaveAs(MapPath("NewImages") + "\\" + strImgFileName);
                System.Drawing.Image img = System.Drawing.Image.FromFile(MapPath("NewImages") + "\\" + strImgFileName);
                img = img.GetThumbnailImage(130, 100, null, IntPtr.Zero);
                img.Save(MapPath("Thumb") + "\\" + strImgFileName);
                Image4.ImageUrl = "Thumb/" + strImgFileName;
                Label5.Text = strImgFileName;
                //  Session["strImgpath"] = strImgFileName;
            }
        }
        protected void Button5_Click(object sender, EventArgs e)
        {
            Response.Redirect("videofrm.aspx");
        }
        protected void Button6_Click(object sender, EventArgs e)
        {
            SqlConnection cnn = new SqlConnection();
            cnn.ConnectionString = "Data Source=.;Initial Catalog=ShadiVivah;Integrated Security=True";

            cnn.Open();

            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "Select * from photo_url";

            cmd.Connection = cnn;


            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;

            DataSet ds = new DataSet();

            da.Fill(ds, "photo_url");

            SqlCommandBuilder cbld = new SqlCommandBuilder(da);

            DataRow drow = ds.Tables["photo_url"].NewRow();


            drow["Photo_Url1"] = Label2.Text;
            drow["Photo_Url2"] = Label3.Text;
            drow["Photo_Url3"] = Label4.Text;
            drow["Photo_Url4"] = Label5.Text;
            drow["regno"] = Label7.Text;

            ds.Tables["photo_url"].Rows.Add(drow);

            da.Update(ds, "photo_url");

            Response.Write("<script>alert('Saved')</script>");

            cnn.Close();
        }
    }


    No comments:

    Post a Comment