Wednesday, February 8, 2012

Display information of uploaded file

Display the information of uploaded file

The following program will display some information of uploaded file. Add the code into any ASP.NET file.
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Upload" /></div>

It will create a file upload control and one upload button. Now add the below code within button’s Click event.

protected void Button1_Click(object sender, EventArgs e)
        if (FileUpload1.HasFile)
                FileUpload1.SaveAs("D:\\" + FileUpload1.FileName);
                Response.Write("File size-" + FileUpload1.PostedFile.ContentLength + "<br/>");
                Response.Write("File Type-" + FileUpload1.PostedFile.ContentType + "<br/>");
            catch (Exception ex)


It will print some information about file ,which is just uploaded in your D drive.

No comments:

Post a Comment