Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

.

aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"
Inherits="_Default"%>
<!DOCTYPEhtmlPUBLIC"//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<tablecellpadding="0"cellspacing="0"width="80%"align="center"border="4">
<tr><tdheight="20px"></td></tr>
<tr><tdheight="200px"align="center"valign="middle">
<inputid="MyFile"type="file"size="81"name="File1"runat="server"/>
<br/><br/>
<asp:Buttonid="btnSubmit"runat="server"Text="Submit"
Width="139px"Height="30px"OnClick="btnSubmit_Click"></asp:Button>
<asp:Labelid="lbl"runat="server"Width="402px"
Height="33px"></asp:Label>
<br/>
<br/>
<br/>
<asp:ImageID="Image1"runat="server"/>
</td></tr></table>
</div>
</form>
</body>
</html>

.aspx.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
publicpartialclass_Default:System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
}
protectedvoidbtnSubmit_Click(objectsender,EventArgse)
{
if(MyFile.PostedFile.ContentLength==0)
{
lbl.Text="Cannotuploadzerolengthfile";
return;
}
lbl.Text=MyFile.PostedFile.FileName;
MyFile.PostedFile.SaveAs(Server.MapPath("Pict1.jpg"));
Image1.ImageUrl="Pict1.jpg";
}
}

You might also like