Saturday, 18 February 2012

Check uploaded file size using C#


 protected void Button1_Click(object sender, EventArgs e)
    {
        long maxsize = 1048576;
        string fileName = Path.GetFullPath(FU.PostedFile.FileName);
        Session["SS"] = fileName;  
        FileInfo f = new FileInfo(Session["SS"].ToString());
        long s1 = f.Length;
        long fs = (s1 / 1024) / 1024;
        if (s1 > maxsize)
        {
            Response.Write("File Size '" + fs.ToString("00.00") + "'KB Exceded");        
            FU.Focus();
        }
        else
        {
            Response.Write("File'" + Session["SS"].ToString() + "' Uploded Sucessfully");      
        }     
    }

No comments:

Post a Comment