Uploading the limited size of file in asp.net. File size is 6MB.

Bageshkumarbagi
Posted by Bageshkumarbagi under ASP.NET category on | Points: 40 | Views : 1833
==========HTML CODE =============
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Upload file up to 6MB</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /><br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>

===============C# code =======================

protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
if (FileUpload1.PostedFile.ContentLength < 6218595)
{
try
{
Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "<br>" +
FileUpload1.PostedFile.ContentLength + " kb<br>" +
"Content type: " +
FileUpload1.PostedFile.ContentType;
}
catch (Exception ex)
{
Label1.Text = "ERROR: " + ex.Message.ToString();
}
}
else
{
Label1.Text = "File size exceeds maximum limit 6 MB. You must be upload file less than 6MB";
}
}
}

Comments or Responses

Login to post response