Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how do i Filter extensions in FileUpload Control

how do i Filter extensions in FileUpload Control

Scheduled Pinned Locked Moved ASP.NET
question
9 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amit Amit Amit
    wrote on last edited by
    #1

    Hi Friends, i m using FileUpload Control in my page now i want, user not able to upload .exe file for that i need to specify filter fo extensions how do i Filter extensions??? thanks

    Amit Metkar 3i-infotech, Mumbai.

    M N M M A 6 Replies Last reply
    0
    • A Amit Amit Amit

      Hi Friends, i m using FileUpload Control in my page now i want, user not able to upload .exe file for that i need to specify filter fo extensions how do i Filter extensions??? thanks

      Amit Metkar 3i-infotech, Mumbai.

      M Offline
      M Offline
      Michael Sync
      wrote on last edited by
      #2

      No. AFAIK, it's not possible to do that with File Upload control. maybe. you may look around flash or ActiveX control.. I'm sure that HTML file control doesn't have that feature. So, you will have to check the extension at code-behind.

      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

      1 Reply Last reply
      0
      • A Amit Amit Amit

        Hi Friends, i m using FileUpload Control in my page now i want, user not able to upload .exe file for that i need to specify filter fo extensions how do i Filter extensions??? thanks

        Amit Metkar 3i-infotech, Mumbai.

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        Amit.Amit.Amit..... wrote:

        now i want, user not able to upload .exe file for that i need to specify filter fo extensions

        Specifying filter is not possible in file upload control. But you can check the file extension like this and alert user regarding that

        if (File1.PostedFile.FileName.EndsWith(".exe"))
        {
        //Display message
        }
        else
        //Upload


        My Website | Ask smart questions

        1 Reply Last reply
        0
        • A Amit Amit Amit

          Hi Friends, i m using FileUpload Control in my page now i want, user not able to upload .exe file for that i need to specify filter fo extensions how do i Filter extensions??? thanks

          Amit Metkar 3i-infotech, Mumbai.

          M Offline
          M Offline
          metallica_rock10
          wrote on last edited by
          #4

          Use javascript for the validations since u cant filter the HtmlInputFile control. Ask if u want the code. u have 2 do it in the onchange method.

          C 1 Reply Last reply
          0
          • A Amit Amit Amit

            Hi Friends, i m using FileUpload Control in my page now i want, user not able to upload .exe file for that i need to specify filter fo extensions how do i Filter extensions??? thanks

            Amit Metkar 3i-infotech, Mumbai.

            M Offline
            M Offline
            metallica_rock10
            wrote on last edited by
            #5

            Use javascript for the validations since u cant filter the HtmlInputFile control. Ask if u want the code u have 2 do it in the onchange method.

            1 Reply Last reply
            0
            • M metallica_rock10

              Use javascript for the validations since u cant filter the HtmlInputFile control. Ask if u want the code. u have 2 do it in the onchange method.

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              javascript cannot interact with the input control, or the file system, AFAIK.

              Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

              M 1 Reply Last reply
              0
              • A Amit Amit Amit

                Hi Friends, i m using FileUpload Control in my page now i want, user not able to upload .exe file for that i need to specify filter fo extensions how do i Filter extensions??? thanks

                Amit Metkar 3i-infotech, Mumbai.

                M Offline
                M Offline
                mangrovecm
                wrote on last edited by
                #7

                you should use this code: private bool IsAccept(string fileName) { bool ok = false; string ext = System.IO.Path.GetExtension(fileName); if (ext == ".jpe" || ext == ".jpeg" || ext == ".pjpeg" || ext == ".gif" || ext == ".jpg" || ext == ".bmp" || ext == ".png" || ext == ".x-png") { ok = true; } return ok; } Hope that help you! vtkiet05

                1 Reply Last reply
                0
                • C Christian Graus

                  javascript cannot interact with the input control, or the file system, AFAIK.

                  Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                  M Offline
                  M Offline
                  Michael Sync
                  wrote on last edited by
                  #8

                  I guess the code vtkiet05 shows us is Server-side code. not Javascript. I believe that that code is not interacting with File System. It's just trying to get the extension of file by using System.IO.

                  Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

                  1 Reply Last reply
                  0
                  • A Amit Amit Amit

                    Hi Friends, i m using FileUpload Control in my page now i want, user not able to upload .exe file for that i need to specify filter fo extensions how do i Filter extensions??? thanks

                    Amit Metkar 3i-infotech, Mumbai.

                    A Offline
                    A Offline
                    Amit Amit Amit
                    wrote on last edited by
                    #9

                    Thank U Friends I got the Solution.... Thanx :):):):):)

                    Amit Metkar 3i-infotech, Mumbai.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups