<cc1:AjaxFileUpload ID="AjaxFileUpload1" AllowedFileTypes="jpg,jpeg"
runat="server" MaximumNumberOfFiles="4" OnUploadComplete="AjaxFileUpload1_UploadComplete"
/>
Code behind file
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
if (e.FileSize > 10)
{
string filePath = e.FileName;
AjaxFileUpload1.SaveAs(Server.MapPath(filePath));
}
else
{
}
}
I want to check that all the files size should not exceed a particular value before the files upload event.
Try this way:
Server side:
and on client side:
Hope this helps!!
See the code below:
The idea is to prevent the file is uploaded to the server. In the proposed solution, when the flow code has reached
afuUpload_UploadedComplete
, the file was uploaded to server, but has not yet been recorded in the path you specify. For example, if the limit is 20 megabytes and the selected file is 22 megabytes, when the code reachesafuUpload_UploadedComplete
, 22 Megabytes already been uploaded to the server.The solution sought is that the validation is done on the client side (JavaScript) and that prevents the code arrives to
CodeBehind
on the server.In my case, I tried to
OnClientUploadComplete
generating an exception when the file size limit is exceeded, but it did not work and the code is still reaching theCodeBehind
. The other problem is that when the exception occurs, the JavaScript functionOnClientUploadError
is not firing to intercept the exception generated inOnClientUploadComplete
function.Controller