Upload Images as Below..
Ans:-
In UploadImages.aspx:-
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="UploadImages.aspx.vb" Inherits="UploadImages" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Image Upload Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<table style="width: 258px; height: 160px" align="center">
<tr>
<td>
<table>
<tr>
<td style="width: 166px" align="center">
<asp:Image ID="ImgMember" runat="server" Height="131px" ImageUrl="~/Images/MemberPhoto.png"
Width="159px" BorderWidth="1px" BorderColor="#400000" BorderStyle="Ridge" />
</td>
</tr>
<tr>
<td style="width: 166px; height: 29px" align="center">
<asp:FileUpload ID="ImageUpload" runat="server" Width="190px" Enabled="true" TabIndex="48"
Height="22px" />
</td>
</tr>
<tr>
<td align="center">
<%--<asp:ImageButton ID="btnUpload" runat="server" AccessKey="U" ToolTip="Alt+u" ImageUrl="~/Images/btnupload.gif" TabIndex="49" />--%>
<asp:UpdatePanel ID="UpdatePanel13" runat="server" UpdateMode="always">
<ContentTemplate>
<asp:Label ID="SubmitButtonLabel" runat="Server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td style="width: 166px" align="center">
<asp:Image ID="ImgMember1" runat="server" Height="131px" ImageUrl="~/Images/MemberPhoto.png"
Width="159px" BorderWidth="1px" BorderColor="#400000" BorderStyle="Ridge" />
</td>
</tr>
<tr>
<td style="width: 166px; height: 29px" align="center">
<asp:FileUpload ID="ImageUpload1" runat="server" Width="190px" Enabled="true" TabIndex="48"
Height="22px" />
</td>
</tr>
<tr>
<td align="center">
<%--<asp:ImageButton ID="btnUpload" runat="server" AccessKey="U" ToolTip="Alt+u" ImageUrl="~/Images/btnupload.gif" TabIndex="49" />--%>
<asp:UpdatePanel ID="UpdatePanel15" runat="server" UpdateMode="always">
<ContentTemplate>
<asp:Label ID="SubmitButtonLabel1" runat="Server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td >
</td>
</tr>
<tr>
<td >
</td>
</tr>
<tr>
<td >
<asp:ImageButton ID="btnUpload" runat="server" AccessKey="U" ToolTip="Alt+u" ImageUrl="~/Images/btnupload.gif" TabIndex="49" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Ans:-
In UploadImages.aspx:-
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="UploadImages.aspx.vb" Inherits="UploadImages" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Image Upload Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<table style="width: 258px; height: 160px" align="center">
<tr>
<td>
<table>
<tr>
<td style="width: 166px" align="center">
<asp:Image ID="ImgMember" runat="server" Height="131px" ImageUrl="~/Images/MemberPhoto.png"
Width="159px" BorderWidth="1px" BorderColor="#400000" BorderStyle="Ridge" />
</td>
</tr>
<tr>
<td style="width: 166px; height: 29px" align="center">
<asp:FileUpload ID="ImageUpload" runat="server" Width="190px" Enabled="true" TabIndex="48"
Height="22px" />
</td>
</tr>
<tr>
<td align="center">
<%--<asp:ImageButton ID="btnUpload" runat="server" AccessKey="U" ToolTip="Alt+u" ImageUrl="~/Images/btnupload.gif" TabIndex="49" />--%>
<asp:UpdatePanel ID="UpdatePanel13" runat="server" UpdateMode="always">
<ContentTemplate>
<asp:Label ID="SubmitButtonLabel" runat="Server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td style="width: 166px" align="center">
<asp:Image ID="ImgMember1" runat="server" Height="131px" ImageUrl="~/Images/MemberPhoto.png"
Width="159px" BorderWidth="1px" BorderColor="#400000" BorderStyle="Ridge" />
</td>
</tr>
<tr>
<td style="width: 166px; height: 29px" align="center">
<asp:FileUpload ID="ImageUpload1" runat="server" Width="190px" Enabled="true" TabIndex="48"
Height="22px" />
</td>
</tr>
<tr>
<td align="center">
<%--<asp:ImageButton ID="btnUpload" runat="server" AccessKey="U" ToolTip="Alt+u" ImageUrl="~/Images/btnupload.gif" TabIndex="49" />--%>
<asp:UpdatePanel ID="UpdatePanel15" runat="server" UpdateMode="always">
<ContentTemplate>
<asp:Label ID="SubmitButtonLabel1" runat="Server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td >
</td>
</tr>
<tr>
<td >
</td>
</tr>
<tr>
<td >
<asp:ImageButton ID="btnUpload" runat="server" AccessKey="U" ToolTip="Alt+u" ImageUrl="~/Images/btnupload.gif" TabIndex="49" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
UploadImages.aspx.vb:-
Imports System.Data
Imports System.Data.SqlClient
Imports System.Exception
Imports System.Drawing
Imports System.Collections
Imports System.Web.UI
Imports System.ComponentModel
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Configuration
Imports System.IO
'Imports Telerik.Web.UI
Partial Class UploadImages
Inherits System.Web.UI.Page
Dim reader As BinaryReader
Dim image() As Byte
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnUpload.Click
Try
If ImageUpload.HasFile Then
Dim nfilesize As Integer = ImageUpload.PostedFile.ContentLength
Dim kb As Integer = nfilesize / 1024
If kb > 10 Then
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Sorry,You can not Upload the file with the Size More than 10Kb for Member Photo');", True) : Exit Sub
End If
Dim SubmitButtonLabel2 As Label = DirectCast(UpdatePanel13.FindControl("SubmitButtonLabel"), Label)
Dim srvPath As String = Server.MapPath("~") & "\Images\" & ImageUpload.FileName
ImageUpload.SaveAs(srvPath)
ViewState("ImgName") = ImageUpload.FileName
ImgMember.ImageUrl = "Images/" & ImageUpload.FileName
reader = New BinaryReader(ImageUpload.PostedFile.InputStream)
image = reader.ReadBytes(ImageUpload.PostedFile.ContentLength)
ViewState("image") = image
End If
If ImageUpload1.HasFile Then
Dim nfilesize As Integer = ImageUpload1.PostedFile.ContentLength
Dim kb As Integer = nfilesize / 1024
If kb > 10 Then
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Sorry,You can not Upload the file with the Size More than 10Kb for Member Photo');", True) : Exit Sub
End If
Dim SubmitButtonLabel1 As Label = DirectCast(UpdatePanel15.FindControl("SubmitButtonLabel1"), Label)
Dim srvPath As String = Server.MapPath("~") & "\Images\" & ImageUpload1.FileName
ImageUpload1.SaveAs(srvPath)
ViewState("ImgName") = ImageUpload1.FileName
ImgMember1.ImageUrl = "Images/" & ImageUpload1.FileName
reader = New BinaryReader(ImageUpload1.PostedFile.InputStream)
image = reader.ReadBytes(ImageUpload1.PostedFile.ContentLength)
ViewState("image") = image
End If
Catch ex As Exception
'lblResult.Text = ex.Message
End Try
End Sub
End Class
No comments:
Post a Comment