using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.IO;
using System.Configuration;

namespace uploadfile
{
    public partial class Uploadfile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {



            if (FileUpload1.HasFile)
            {
                 
                        int filesize = FileUpload1.PostedFile.ContentLength;
                        if (filesize < 104857600)
                        {
                            FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Data/") + FileUpload1.FileName);
                            string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
                            string detail = TextBox3.Text;
                            string filetype = FileUpload1.PostedFile.ContentType;
                            string cs = ConfigurationManager.ConnectionStrings["uploadfile"].ConnectionString;
                            string name = TextBox1.Text;
                            string Facilitator = TextBox10.Text;
                            SqlConnection con = new SqlConnection(cs);
                            SqlCommand cmd = new SqlCommand();
                            cmd.CommandText = "insert into Table2(Name,Type,Tages,Facilitator)values(@Name,@Type,@Tages,@Facilitator)";
                            cmd.Parameters.AddWithValue("@Name", filename);
                            cmd.Parameters.AddWithValue("@Type", detail);

                            cmd.Parameters.AddWithValue("@Tages", name);
                            cmd.Parameters.AddWithValue("@Facilitator", Facilitator);

                            cmd.Connection = con;
                            con.Open();
                            cmd.ExecuteNonQuery();
                            con.Close();
                            Label1.ForeColor = System.Drawing.Color.Green;
                            Label1.Text = "Your File Is Successfully Uploaded....";
                        }
                        else
                        {
                            Label1.ForeColor = System.Drawing.Color.Green;
                            Label1.Text = "Your File  is larger than  mb....";
                        }

                  
                
                
                
            }
            else
            {
                Label1.ForeColor = System.Drawing.Color.Red;
                Label1.Text = "Please select the file first then click the upload button....";

            }
        }

        protected void TextBox3_TextChanged(object sender, EventArgs e)
        {

        }

    }
}