follow the instruction
1. Drag a file upload control and one button in source code
2. Drag a image control to show the uploaded image
3.Create a folder name it img
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUploadControl"
runat="server"
/>
<asp:Button ID="btnUpload"
runat="server"
Text="Upload"
onclick="btnUpload_Click"
/>
<br />
<br />
<asp:Image ID="Myimage"
runat="server"
/>
</div>
</form>
4. copy the code behind below at your button click event
protected void
btnUpload_Click(object sender, EventArgs e)
{
if (FileUploadControl.HasFile)
{
string filename = Path.GetFileName(FileUploadControl.FileName);
FileUploadControl.SaveAs(Server.MapPath("~/img/")+filename);
Myimage.ImageUrl = "~/img/"
+ filename;
}
}
No comments:
Post a Comment