MaxBytes Property

Object: SoftArtisans.FileUp
Syntax: MaxBytes
Type: Long Integer
Read/Write: Read/Write
Description:

This property defines the maximum number of bytes that are written to disk or into the database on a per-filebasis.

This important property prevents malicious users from filling your web server's hard disk.

If a user uploads a file larger than MaxBytes, no error is reported. Instead, writing stops at exactly that value. For example, if MaxBytes is set to 200, and the user uploads a file that is 300 bytes long, only the first 200 bytes are written to the web server's hard disk.

Each individual file in the upload has this limit. For example, if there are three files in a single form and MaxBytes is set to 500:

File Original Size  Written Size
file1 1000 500
file2 200 200
file3 600 500

Setting MaxBytes to zero (0) implies no limit. This is the default value.

You can also use MaxBytes in conjunction with the SaveBinaryAs method .

Note: When using the HttpModule with an ASP.NET upload, use the MaxBytes registry key instead of this property. Since the HttpModule is used for caching, this property will not affect the uploaded file.

For discussion and code samples on limiting the upload size, please see:

See also, MaxBytesToCancel.

Examples:
ASP <%
fileUpload.MaxBytes = 300000
fileUpload.SaveAs filename
%>
ASP.NET N/A - Use MaxBytes registry key.

Copyright © 2010 SoftArtisans, Inc. All rights reserved.