| Author: muralidhar 27 Sep 2008 | Member Level: Gold | Rating:   Points: 3 |
hai,
you can get the file size of the uploading file by using
FileUpload1.PostedFile.ContentLength;
the above statement will give you the file size.
file can be of any type(doc, rtf, jpg,gif etc).
regards, Muralidhar.
Regards, Muralidhar.
|
| Author: puneet 27 Sep 2008 | Member Level: Bronze | Rating: Points: 1 |
FileUpload1.PostedFile.ContentLength
it will
give the size of file
|
| Author: Ravi Kiran Nedunuri 27 Sep 2008 | Member Level: Gold | Rating:     Points: 15 |
hi please check all the details regarding file upload conrol
declare a file upload and span in .aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUpload.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <table> <tr> <td> please upload a image:</td> <td> <asp:FileUpload ID="fileup" runat="server" /></td> </tr> <tr> <td colspan="2" align="center"> <asp:Button ID="btnFileup" runat="server" Text="save" OnClick="btnFileup_Click" /></td> </tr> </table> </div> <span id="sp" runat="server"> FileName: <asp:Label ID="lblFileName" runat="server"></asp:Label> <br /> ImageType: <asp:Label ID="lblImgType" runat="server"> </asp:Label> <br /> Image Saved At: <asp:Label ID="lblPath" runat="server"></asp:Label> <br /> <asp:Label ID="lblMessage" runat="server"></asp:Label> <br /> </span> </form> </body> </html> in code behind write the following code
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;
public partial class Default3 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { sp.Visible = false; } protected void btnFileup_Click(object sender, EventArgs e) { if (fileup.PostedFile.ContentLength > 0) { if (fileup.PostedFile.FileName.EndsWith(".bmp") || fileup.PostedFile.FileName.EndsWith(".gif") || fileup.PostedFile.FileName.EndsWith(".png") || fileup.PostedFile.FileName.EndsWith(".jpeg") || fileup.PostedFile.FileName.EndsWith(".jpg")) {
string s = Server.MapPath("images\\");//this saves the image in our application where our project is located.(saves in images folder) fileup.PostedFile.SaveAs(s ); lblFileName.Text = fileup.FileName.ToString();//Water lilies.jpg //lblFileName.Text = fileup.PostedFile.FileName.ToString(); C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water lilies.jpg lblImgType.Text = fileup.PostedFile.ContentType.ToString(); lblPath.Text = s; lblMessage.Text = "upload suceess"; sp.Visible = true; }
else { sp.Visible = false; Response.Write("invalid image format"); //ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('Invalid Image Format');</script>'"); } } } } Regards N.RaviKiran
|