This is a migrated thread and some comments may be shown as answers.

Client-side set allowed file extensions

5 Answers 294 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 05 Apr 2013, 10:04 PM
I was hoping to set the allowed file extensions based on some chosen radio buttons, but the sample code in the on-line documentation does not work. I am weak in my javascript, so I am probably missing something simple. Here's the documentation page:
http://www.telerik.com/help/aspnet-ajax/asyncupload-client-object.html

and here's the sample code it provides:
function AllowJPEGExtension() {
  var upload = $find("<%= RadAsyncUpload1.ClientID %>");
 
  if (!upload.isExtensionValid(".jpeg"))
  {
     var exts = upload.get_allowedFileExtensions();
     exts[exts.length] = ".jpeg";
  }
}

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Apr 2013, 01:11 PM
Hi,

I guess you need to allow file extensions based on the radio button selection. Here is the code I tried from server side which worked as expected.

ASPX:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal"
    AutoPostBack="true" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
    <asp:ListItem Text="jpg"></asp:ListItem>
    <asp:ListItem Text="doc"></asp:ListItem>
    <asp:ListItem Text="pdf"></asp:ListItem>
</asp:RadioButtonList>
<br />
<telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server">
</telerik:RadAsyncUpload>

C#:
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
    string file = RadioButtonList1.SelectedItem.Text;
    RadAsyncUpload1.AllowedFileExtensions = new string[] {file};
}

Thanks,
Princy.
0
Scott
Top achievements
Rank 1
answered on 14 Apr 2013, 07:38 PM
Thank you Princy for providing a server-side solution.  Does anyone have a client-side solution?
0
Accepted
Plamen
Telerik team
answered on 17 Apr 2013, 12:19 PM
Hello Scott,

 
RadAsyncUpload does not support such client change in the allowed extensions because it would cause a security by providing possibility to upload unwanted files. 

In your scenario since you only want to control this behavior with radio button instead of using the "AllowedFileExtensions" you can use OnClientFileUploading event and cancel the uploading file if its extension is not the desired one as in the code below:

function OnClientFileUploading(sender, args) {
               var fileExtention = args.get_fileName().substring(args.get_fileName().lastIndexOf('.') + 1, args.get_fileName().length);
               alert(fileExtention);
           }

Please have in mind that this can easily be overriden so if you strongly need this validation you will have to use server-side way described earlier.

Hope this will explain the issue.
All the best,
Plamen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Scott
Top achievements
Rank 1
answered on 22 Apr 2013, 09:09 PM
Thank you Plamen.  If possible, you may want to request a change to the documentation, since the sample code I mentioned is apparently wrong.
0
Plamen
Telerik team
answered on 23 Apr 2013, 04:56 AM
Hi Scott,

 
I already did this. Thank you very much for your concern with Telerik controls.

All the best,
Plamen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
AsyncUpload
Asked by
Scott
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Scott
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or