How to get the file size in client side?

ajeeshco

Well-known member
Joined
Sep 19, 2006
Messages
257
Location
Cochin, India
Programming Experience
3-5
Hi,
I'm using fileupload control to upload files. Now I would like to restrict the users from uploading files of size greater than 15 mb without having a trip to server. How can I do this? Do I have to use ActiveX components if so, can you mention some components.

Thanks in Advance.
 
Check the PostedFile.ContentLength and determine if you will allow the upload or not.
VB.NET:
    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        If FileUpload1.HasFile Then
            If FileUpload1.PostedFile.ContentLength < 150000 Then
                Dim filename As String = IO.Path.GetFileName(FileUpload1.PostedFile.FileName)
                FileUpload1.PostedFile.SaveAs(Server.MapPath(filename))
            Else
                Label1.Text = "File too large, max upload size is 150KB"
            End If
        End If
    End Sub
 
Back
Top