0% found this document useful (0 votes)
27 views2 pages

Image Upload

This document contains code for an ASP.NET web form that allows users to upload an image file. The form includes a file input, submit button, and label. When the button is clicked, the code saves the uploaded file to the server and displays the image on the page. Validation checks that a file is selected before attempting to save.

Uploaded by

mkbhaduri
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views2 pages

Image Upload

This document contains code for an ASP.NET web form that allows users to upload an image file. The form includes a file input, submit button, and label. When the button is clicked, the code saves the uploaded file to the server and displays the image on the page. Validation checks that a file is selected before attempting to save.

Uploaded by

mkbhaduri
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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