Hi,
I have a RadAsyncUpload control, i want to upload the file to target folder only on click of upload button. SO i have st the ManualUpload attribute to false. Actually On clicking upload button, i have a function to find the (total size of target folder + uploaded file size). if it exceeds than 50MB, i need to cancel the upload event. I can find the size, but i dont know how to cancel the upload event in c# code.Help me with this
Regards,
Farjana
I have a RadAsyncUpload control, i want to upload the file to target folder only on click of upload button. SO i have st the ManualUpload attribute to false. Actually On clicking upload button, i have a function to find the (total size of target folder + uploaded file size). if it exceeds than 50MB, i need to cancel the upload event. I can find the size, but i dont know how to cancel the upload event in c# code.Help me with this
Regards,
Farjana
4 Answers, 1 is accepted
0

A2H
Top achievements
Rank 1
answered on 21 Nov 2013, 01:55 AM
Hi,
You can use the OnFileUploaded event and if the e.File.ContentLength is greater than 50 MB to set the "IsValid" property to false.
Check the Validation online demo where a similar functionality is implemented.
Sample Code
You can use the OnFileUploaded event and if the e.File.ContentLength is greater than 50 MB to set the "IsValid" property to false.
Check the Validation online demo where a similar functionality is implemented.
Sample Code
public
void
RadAsyncUpload1_FileUploaded(
object
sender, FileUploadedEventArgs e)
{
const
int
MaxTotalBytes = 52428800;
// 50 MB
long
totalBytes;
var liItem =
new
HtmlGenericControl(
"li"
);
liItem.InnerText = e.File.FileName;
if
(totalBytes < MaxTotalBytes)
{
// Total bytes limit has not been reached, accept the file
e.IsValid =
true
;
totalBytes += e.File.ContentLength;
}
else
{
// Limit reached, discard the file
e.IsValid =
false
;
}
if
(e.IsValid)
{
ValidFiles.Visible =
true
;
ValidFilesList.Controls.AddAt(0, liItem);
}
else
{
InvalidFiles.Visible =
true
;
InValidFilesList.Controls.AddAt(0, liItem);
}
}
0

Farjana
Top achievements
Rank 1
answered on 26 Nov 2013, 05:38 AM
Hello,
Thanks for suggesting the solution. But the solution u gave validates the entire size in client side while uploading the files. What i actually need is, I have some files to be attached at different times for the same order. The overall size of uploads should not be more than 50MB, so it should first calculate the size of folder in directory in the server and while uploading a new file to the same order, it should check if the sum of files already uploaded exceeds more than 50MB. If so, it should not upload the file. Suggest any event to cancel the upload after knowing that the sum of uploads exceeds 50MB.
Thanks.
Thanks for suggesting the solution. But the solution u gave validates the entire size in client side while uploading the files. What i actually need is, I have some files to be attached at different times for the same order. The overall size of uploads should not be more than 50MB, so it should first calculate the size of folder in directory in the server and while uploading a new file to the same order, it should check if the sum of files already uploaded exceeds more than 50MB. If so, it should not upload the file. Suggest any event to cancel the upload after knowing that the sum of uploads exceeds 50MB.
Thanks.
0

Shinu
Top achievements
Rank 2
answered on 26 Nov 2013, 09:05 AM
Hi Farjana,
Please have a look into the following code snippet to cancel the upload when maximum file size reaches.
ASPX:
C#:
JavaScript:
Thanks,
Shinu.
Please have a look into the following code snippet to cancel the upload when maximum file size reaches.
ASPX:
<
telerik:RadAsyncUpload
ID
=
"RadAsyncUpload1"
runat
=
"server"
TargetFolder
=
"Uploads"
OnFileUploaded
=
"RadAsyncUpload1_FileUploaded"
OnClientFileUploading
=
"OnClientFileUploading"
>
</
telerik:RadAsyncUpload
>
<
telerik:RadButton
ID
=
"RadButton1"
runat
=
"server"
Text
=
"Save File"
>
</
telerik:RadButton
>
<
asp:HiddenField
ID
=
"HiddenField1"
runat
=
"server"
Value
=
"0"
/>
C#:
protected
void
RadAsyncUpload1_FileUploaded(
object
sender, Telerik.Web.UI.FileUploadedEventArgs e)
{
string
path = Server.MapPath(RadAsyncUpload1.TargetFolder);
DirectoryInfo dir =
new
DirectoryInfo(path);
long
size= dir.EnumerateFiles(
"*"
, SearchOption.AllDirectories).Sum(fi => fi.Length);
if
(size > 52428800)
{
e.IsValid =
false
;
HiddenField1.Value =
"1"
;
}
else
{
e.File.SaveAs(Path.Combine(Server.MapPath(RadAsyncUpload1.TargetFolder), e.File.FileName));
}
}
JavaScript:
<script type=
"text/javascript"
>
function
OnClientFileUploading(sender, args) {
var
hidden = document.getElementById(
"HiddenField1"
).value;
if
(hidden ==
"1"
) {
args.set_cancel(
true
);
alert(
"Maximum File Size reaches"
);
}
}
</script>
Thanks,
Shinu.
0

S
Top achievements
Rank 1
answered on 29 Aug 2017, 07:06 PM
1. Is uploading 900 GB (Yes GB) possible with this control?
2. In case of such a large file, what would happen to the server resources - does it directly write to the IO stream or keeps entire file in the memory?
Use Case: Client has 3D files and Video Files.