UploadNotic.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UploadNotic.aspx.cs" Inherits="UploadNotic" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
height: 226px;
}
.auto-style2 {
width: 81px;
}
.auto-style3 {
width: 81px;
height: 35px;
}
.auto-style4 {
height: 35px;
}
</style>
</head>
<body style="height: 460px">
<form id="form1" runat="server">
<div>
<br />
<br />
<br />
<table class="auto-style1">
<tr>
<td class="auto-style3">
<asp:Label ID="Label5" runat="server" Text="ID" Font-Bold="True"></asp:Label>
</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox3" runat="server" TabIndex="1" Width="242px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style3">
<asp:Label ID="Label1" runat="server" Text="Date" style="font-weight: 700"></asp:Label>
</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox1" runat="server" TabIndex="2" TextMode="Date" Width="242px" ></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style3">
<asp:Label ID="Label2" runat="server" Text="Subject" style="font-weight: 700"></asp:Label>
</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox2" runat="server" TabIndex="3" Width="242px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="Label3" runat="server" Text="Content" style="font-weight: 700"></asp:Label>
</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" TabIndex="4" Width="246px" />
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td>
<asp:Label ID="Label4" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="SUMIT" TabIndex="5" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
UploadNotic.aspx.cs
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;
public partial class UploadNotic : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
String cs=ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
SqlConnection sqlcon = new SqlConnection(constring);
FileUpload1.SaveAs(Server.MapPath("~/Upload/") + Path.GetFileName(FileUpload1.FileName));
String link = "Upload/" + Path.GetFileName(FileUpload1.FileName);
String query = "Insert into tbl_Notice(ID,DATE,SUBJECT,CONTENT) values('" + TextBox3.Text + "','" + TextBox1.Text + "','" + TextBox2.Text + "','" + link + "')";
SqlCommand cmd = new SqlCommand(query, sqlcon);
sqlcon.Open(); ;
cmd.ExecuteNonQuery();
sqlcon.Close();
Label4.Text = "Data Has Been Saved Successfully";
}
}
0 Comments