Wednesday, February 8, 2012

Upload large file in ASP.Net

Upload a large file in ASP.Net

To upload a large file using ASP.Net 2.0 you have to configure web.xml file. Add the following code in your web.config file.
 apartmentThreading="false" />

The parameter maxRequestLength control maximum size of file allow to upload. Change the parameter value according to your requirement. Now you can allow to upload your won favorite file.
Add the content in a ASP.Net page.

<%@ 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>

Now add the content in 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)


No comments:

Post a Comment