Filetype filter (.pdf, .doc)...etc

8 posts, 0 answers
  1. Bob
    Bob avatar
    7 posts
    Member since:
    Jun 2012

    Posted 01 Dec 2012 Link to this post

    Is there a way to only allow the user to control the selectable file types?

    I know I can get the information once they select the file but I'd prefer to filter the list to only .pdf, or whatever.
  2. Dimo
    Admin
    Dimo avatar
    8333 posts

    Posted 04 Dec 2012 Link to this post

    Hello Bob,

    You can use an accept HTML attribute, but keep in mind it is only supported by modern browsers.


    @(Html.Kendo().Upload()
        .Name("files")
        .HtmlAttributes(new { accept = "image/*" })
    )


    Regards,
    Dimo
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Igor
    Igor avatar
    145 posts
    Member since:
    Jan 2011

    Posted 10 Oct 2013 Link to this post

    Hi!

    here is also one idea that might be useful for somebody
    i have not tested if it could filter filesize, but i suspect so.
    @(Html.Kendo().Upload()
     .Name("docUpload")
     .Multiple(false)
      .ShowFileList(false)
      .Events(e => e.Upload("onUpload"))
      .Async(a => a
            .Save("DocUpload", "Documents")
             .AutoUpload(true))
    )
     
    <script>
      function onUpload(e) {
            var files = e.files;
     
            $.each(files, function () {
     
                if (this.extension.toLowerCase() != ".doc") {
                    alert("Only .doc files can be uploaded!")
                    e.preventDefault();
                }
     
                if (this.size / 1024 / 1024 > 5) {
                    alert("Max 5Mb file size is allowed!")
                    e.preventDefault();
                }
            });
        }
    </script>


  5. Francis
    Francis avatar
    5 posts
    Member since:
    Jan 2014

    Posted 20 Feb 2014 Link to this post

    I would like the user to be able select only certain file types.  For instance, ".csv" | ".xlsx" | "*.* All files".  How do I achieve this?
  6. Igor
    Igor avatar
    145 posts
    Member since:
    Jan 2011

    Posted 20 Feb 2014 in reply to Francis Link to this post

    Well, according to documentation it is not possible yet to configure the file open dialog box.
    You could only "catch" the upload event in order to have file extensions be filtered:
    http://docs.telerik.com/kendo-ui/api/web/upload#events-upload

    or you may use and alternative way to have extensions like that with jQuery:
    http://stackoverflow.com/questions/8938124/how-to-filter-input-type-file-dialog-by-specific-file-type
  7. krishna
    krishna avatar
    4 posts
    Member since:
    Jan 2015

    Posted 31 Mar 2015 in reply to Igor Link to this post

    Is there any way yet, on how to configure the file open dialogue box as Igor said ?
    I need to display the file extensions allowed, in the dropdown of that dialogue box, so that user can sort the files accordingly !
    Kindly respond.
  8. krishna
    krishna avatar
    4 posts
    Member since:
    Jan 2015

    Posted 31 Mar 2015 in reply to Dimo Link to this post

    Is there any way yet, on how to configure the file open dialogue box as Igor said ?
    I need to display the file extensions allowed, in the dropdown of that dialogue box, so that user can sort the files accordingly !
    Kindly respond.
  9. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 31 Mar 2015 Link to this post

    Hello Gopikrishna,

    You could use the accept html attribute to specify the files that should be displayed by default in the file selection window, but it it not possible to restrict the user from selecting another one by changing the value in the file types dropdown.

    Regards,
    Dimiter Madjarov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
UI for ASP.NET MVC is VS 2017 Ready