Step1: Drag and drop a file uploader and a button control to your form.
Eg:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Home.aspx.cs" Inherits="Home" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<p style="margin-bottom: 0px">
FILE UPLOAD
</p>
<p style="margin-bottom: 0px">
ADD FILE <asp:FileUpload ID="FileUpload1" runat="server" style="margin-bottom: 0px" />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="SUBMIT"
style="height: 26px" />
</p>
</form>
</body>
</html>
Step 2:
Select solution explorer & create a new folder and name it as Img
Step 3:
Double Click on the submit button
In the code behind window add the following code on the click event
protected void Button1_Click(object sender, EventArgs e)
{
FileUpload1.SaveAs(Server.MapPath("~/Img/") + FileUpload1.FileName);
}
Step 4:
Run
Step 5:
Refresh the Img folder in the solution Explorer
0 comments:
Post a Comment