-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangephoto.aspx
54 lines (46 loc) · 1.66 KB
/
changephoto.aspx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
protected void btnSubmit_Click(object sender, EventArgs e)
{
// check whether file is uploaded
if (!FileUpload1.HasFile)
{
lblMsg.Text = "Please select your photo file!";
return;
}
SqlConnection con = new SqlConnection(Database.ConnectionString);
try
{
String filename = Request.MapPath("photos/" + Session["uid"].ToString() + ".jpg");
FileUpload1.SaveAs(filename);
// update PHOTO column
con.Open();
SqlCommand cmd = new SqlCommand("update users set photo = 'y' where uid = " + Session["uid"].ToString(), con);
if (cmd.ExecuteNonQuery() == 1)
lblMsg.Text = "Photo is uploaded successfully!";
else
lblMsg.Text = "Sorry! Could not upload photo. Please try again!";
}
catch (Exception ex)
{
lblMsg.Text = "Error->" + ex.Message;
}
finally
{
con.Close();
}
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<h2>
Change Photo</h2>
<p>
Select your photo :
<asp:FileUpload ID="FileUpload1" runat="server" /></p>
<p>
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" /> </p>
<p>
<asp:Label ID="lblMsg" runat="server"></asp:Label> </p>
</asp:Content>