I have an issue in the asyncupload. I am uploading a file and checking the file name through database that it is existing or not and i am doing this through the javascript pagemethod. But through the pagemethod i just want to remove the file on a particular condition.
Like
function ToResetValidation(sender, eventArgs) {
var FileName = eventArgs.get_fileName().split('.').reverse().slice(1).reverse().join('.');
PageMethods.GetFileName(FileName, Onsucess);
}
function Onsucess(result) {
if (result == 1) {
alert('This file is already exsist');
********* // Here i have to remove the file from uploader on clientside ******* CONDITION
return false;
}
}
<telerik:RadAsyncUpload ID="RUImage" OnClientDeleting="ToDeleteFile" runat="server"
AllowedFileExtensions=".pdf,.doc,.docx" ControlObjectsVisibility="None" InputSize="35" Width="300px" style="float:left; margin-top:5px; "
Font-Names="Arial" MaxFileSize="5242880" OnClientFileUploaded="ToResetValidation"
AutoAddFileInputs="true" OnClientValidationFailed="validationFailed" MaxFileInputsCount="1"
TabIndex="4" >
</telerik:RadAsyncUpload>
Thanks
Manish
12 Answers, 1 is accepted
Please review the following sample code. Please cancel the upload when OnClientFileUploading event is fired.
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
telerik:RadScriptManager
runat
=
"server"
ID
=
"RadScriptManager"
></
telerik:RadScriptManager
>
<
telerik:RadAsyncUpload
runat
=
"server"
ID
=
"RadAsyncUpload1"
OnClientFileUploading
=
"onClientFileUploading"
MultipleFileSelection
=
"Automatic"
></
telerik:RadAsyncUpload
>
</
div
>
</
form
>
<
script
type
=
"text/javascript"
>
function onClientFileUploading(sender, args) {
var test = args.get_fileName();
if(test.length > 10)
sender._cancelUpload(args.get_row());
}
</
script
>
Greetings,
Peter Filipov
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
When I used the sample code you provided I got the error:
Uncaught Error: Error calling method on NPObject.
Can you help with it?
Thanks,
Charlie
That functionality is not officially supported. When using IFrame/Silverlight to upload files with RadAsyncUpload it is possible to cancel the upload when the OnClientFileUploading event is fired. Please disable Flash module with the following sample code:
Telerik.Web.UI.RadAsyncUpload.Modules.Flash.isAvailable =
function
() {
return
false
; };
That functionality will be implemented officially.
Kind regards,
Peter Filipov
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
Yes that worked.
What if I want to check file name BEFORE file is sent to the server? I use the code you provided on OnClientFileSelected event and got loads of error including Uncaught Error: Error calling method on NPObject.
Any Ideas?
Thanks,
Charlie
Please clarify which version of our controls and browser are you using? Could you please check which module are you using to upload files (right button click on the file input)?
Best wishes,
Peter Filipov
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
Right I use sender._cancelUpload(args.get_row())in the OnClientFilesSelected event which caused the error.
But if I use it in the OnClientFileUploading event, the file will still be uploaded to server.
I know I can stop file uploading in the OnClientFilesSelected event, but inside this event I can not get the selected filename. Also it will cancel all files to be uploaded. What if I multi-select 3 files and just want to cancel one of them? OnClientFileSelected event doesn't support cancel function.
I am using version Q1 2011.
Please help.
Thanks,
Charlie
For the next service pack it will be possible to cancel the uploading event with every module FileApi/Silverligh/Flash/IFrame and the file is not going to be uploaded. In the OnClientFileSelected event handler it is not possible to use the
_cancelUpload
method.Greetings,
Peter Filipov
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
with sender._cancelUpload(args.get_row()); we can cancel uploading of file, but files will be there in
$find(RadAsyncUpload1).getUploadedFiles()
How to get canceled files or remove it from getUploadedFiles()?
Thanks
Here is the code that should help you remove the canceled file:
function
OnClientFileUploading(sender, args) {
sender._cancelUpload(args.get_row());
sender._updateCancelButton(args.get_row());
$telerik.$(
".ruRemove"
, args.get_row()).click();
}
Hope this will be helpful.
Greetings,
Plamen
the Telerik team
appreciate your help.
In case of Multiple file selection I moved that code in OnClientFileUploaded(sender, args) event. and it;s working fine.
Thanks
I modified it to behave only when ".ruCancel" is clicked." I'm not sure if this is exactly right, but it seems to work.
Please correct as necessary.
window.onClientFileUploading =
function
(sender, args) {
$(
".ruCancel"
, args.get_row()).click(
function
() {
sender._cancelUpload(args.get_row());
sender._updateCancelButton(args.get_row());
$(
".ruRemove"
, args.get_row()).click();
});
}
The code seems correct. If you experience some issues let me know.
Regards,
Plamen
Telerik