CODE: file-upload-example.aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="fuImage" runat="server" />
<br />
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
<br />
<br />
<asp:Label ID="lblMsg" runat="server" Text="[Message]"></asp:Label>
</div>
</form>
</body>
</html>
CODE: file-upload-example.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class file_upload_sample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if ((fuImage.PostedFile != null) && (fuImage.PostedFile.ContentLength > 0))
{
string FileName = System.IO.Path.GetFileName(fuImage.FileName);
string FileSaveLocation = @"F:\Learning\UserFiles\" + FileName;
fuImage.PostedFile.SaveAs(FileSaveLocation);
lblMsg.Text = "File Uploaded Successfully";
}
}
}
No comments:
Post a Comment