For uploading files to server using the new FileUpload control in C#,

<%@ Page Language="C#"%>

<script runat="server">
 protected void Button1_Click(object sender, EventArgs e)
 if (FileUpload1.HasFile)
 try {
 FileUpload1.SaveAs("C:\\Uploads\\" + FileUpload1.FileName);
 Label1.Text = "File name: " +
 FileUpload1.PostedFile.FileName + "<br>" +
 FileUpload1.PostedFile.ContentLength + " kb<br>" +
 "Content type: " +
 catch (Exception ex) {
 Label1.Text = "ERROR: " + ex.Message.ToString();
 Label1.Text = "You have not specified a file.";

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
 <title>FileUpload Server Control</title>
 <form id="form1" runat="server">
 <asp:FileUpload ID="FileUpload1" Runat="server" />

 <asp:Button ID="Button1" Runat="server" Text="Upload"
 OnClick="Button1_Click" />

 <asp:Label ID="Label1" Runat="server"></asp:Label>


Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.