Upload
IMAGE.ASPX
<%@ Page Language="C#"
AutoEventWireup="true" CodeFile="Upload_photos.aspx.cs"
Inherits="Upload_photos" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body style="font-style: italic">
<form
id="form1" runat="server">
<div>
</div>
<asp:FileUpload ID="FileUpload1" runat="server"
/>
<p>
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server"
Text="plz Enter any image first.."
Visible="False"></asp:Label>
</p>
<p>
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Button" />
</p>
<p>
<asp:Label ID="Label1" runat="server"
Text="PhotoUploaded" Visible="False"></asp:Label>
</p>
</form>
</body>
</html>
UPLOAD
IMAGE.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.Data;
public partial class Upload_photos : System.Web.UI.Page
{
SqlConnection conn
= new SqlConnection(@"Data
Source=(LocalDB)\v11.0;AttachDbFilename=D:\Asp_dot_ne\WebSite3\App_Data\pro_gridview.mdf;Integrated
Security=True");
SqlCommand cmd;
protected void
Page_Load(object sender, EventArgs e)
{
}
protected void
Button1_Click(object sender, EventArgs e)
{
if
(TextBox1.Text == "" || FileUpload1.FileName == "")
{
Label2.Visible = true;
Label1.Visible = false;
}
else
{
conn.Open();
string str
= "~/myupload" + FileUpload1.FileName;
FileUpload1.SaveAs(Server.MapPath(str));
cmd = new
SqlCommand("insert into imgupload values('" + str + "','" +
TextBox1.Text + "')", conn);
cmd.ExecuteNonQuery();
conn.Close();
Label1.Visible = true;
Label2.Visible = false;
}
}
}