Persits Software, Inc. Knowledge Base Articles

Informing user that an uploaded file exceeds the size limit

Problem Description

The solution given in Article PS01092671 does not permit accessing the name of the file that is too large, so that the user can be informed.

When the SetMaxSize method is used with True as the second parameter, AspUpload throws an error instead of adding the file to the Files collection. Therefore, your ASP code cannot access properties of the file that is too large.


The solution is to use SetMaxSize with the second argument as False, so that AspUpload will truncate the file rather than rejecting it with an error. Then your code can iterate through the Upload.Files collection, check to see if the file size equals the specified maximum (which will indicate that truncation occurred), and alert the user.

Set Upload = Server.CreateObject("Persits.Upload")  
Upload.SetMaxSize 50000, False  'limit to 50 KB, do not throw an error  
Upload.Save                     'save to memory

For Each file In Upload.Files
    If file.Size = 50000 Then
        'This means the file was truncated
        Response.Write "This file is too large: " & file.FileName
        file.SaveAs ...
    End If