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. General Programming
  3. C#
  4. how to download .exe files on click of link in asp.net

how to download .exe files on click of link in asp.net

Scheduled Pinned Locked Moved C#
csharpjavascriptasp-nettutorial
8 Posts 5 Posters 1 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.
  • N Offline
    N Offline
    NarVish
    wrote on last edited by
    #1

    In ASP.Net, I'm trying to download one .exe file, on click of hyperlink. I used the following javascript to download or open.. function OpenFile() { window.open("D:/Games/poker.exe", 'FilePopUp', 'resizable=yes,scrollbars=1'); } If I give some other files in place of poker.exe, like .doc, .pdf, the code is working. but unable to download .exe files. Thanks in advance.

    A C V S 4 Replies Last reply
    0
    • N NarVish

      In ASP.Net, I'm trying to download one .exe file, on click of hyperlink. I used the following javascript to download or open.. function OpenFile() { window.open("D:/Games/poker.exe", 'FilePopUp', 'resizable=yes,scrollbars=1'); } If I give some other files in place of poker.exe, like .doc, .pdf, the code is working. but unable to download .exe files. Thanks in advance.

      A Offline
      A Offline
      Anindya Chatterjee
      wrote on last edited by
      #2

      May be it is due to security settings of your web browser, try renaming exe to something else and download it from the same path e.g "D:\Games\poker.dat". If it works then there is security problems due to exe file, otherwise there may be some other problem.

      Anindya Chatterjee

      N 1 Reply Last reply
      0
      • N NarVish

        In ASP.Net, I'm trying to download one .exe file, on click of hyperlink. I used the following javascript to download or open.. function OpenFile() { window.open("D:/Games/poker.exe", 'FilePopUp', 'resizable=yes,scrollbars=1'); } If I give some other files in place of poker.exe, like .doc, .pdf, the code is working. but unable to download .exe files. Thanks in advance.

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

        you're in the wrong forum, but this code is useless, because it will only work if the server is also the machine doing the browsing. No way is IE going to let you run an exe on the local machine. If you want to download an exe, set the content type and use response.binarywrite, then use a path like this to read the file on the file system if you like. In javascript, you'd also redirect to a page that streams the file down.

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        1 Reply Last reply
        0
        • N NarVish

          In ASP.Net, I'm trying to download one .exe file, on click of hyperlink. I used the following javascript to download or open.. function OpenFile() { window.open("D:/Games/poker.exe", 'FilePopUp', 'resizable=yes,scrollbars=1'); } If I give some other files in place of poker.exe, like .doc, .pdf, the code is working. but unable to download .exe files. Thanks in advance.

          V Offline
          V Offline
          Vasudevan Deepak Kumar
          wrote on last edited by
          #4

          LalithaSJ wrote:

          unable to download .exe files

          Can you describe what happens? Do you get an error? What error message are you getting?

          Vasudevan Deepak Kumar Personal Homepage
          Tech Gossips
          A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

          1 Reply Last reply
          0
          • A Anindya Chatterjee

            May be it is due to security settings of your web browser, try renaming exe to something else and download it from the same path e.g "D:\Games\poker.dat". If it works then there is security problems due to exe file, otherwise there may be some other problem.

            Anindya Chatterjee

            N Offline
            N Offline
            NarVish
            wrote on last edited by
            #5

            when I tried to access other files from the same path, it is getting executed successfully. In case of .exe files, I'm getting javascript error saying that Access is denied. Its a security voilation problem. Read-only property of the file is unchecked. Please guide me to solve this problem.

            V 1 Reply Last reply
            0
            • N NarVish

              when I tried to access other files from the same path, it is getting executed successfully. In case of .exe files, I'm getting javascript error saying that Access is denied. Its a security voilation problem. Read-only property of the file is unchecked. Please guide me to solve this problem.

              V Offline
              V Offline
              Vasudevan Deepak Kumar
              wrote on last edited by
              #6

              Do you have an Antivirus that prohibits .EXE downloads?

              Vasudevan Deepak Kumar Personal Homepage
              Tech Gossips
              A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

              1 Reply Last reply
              0
              • N NarVish

                In ASP.Net, I'm trying to download one .exe file, on click of hyperlink. I used the following javascript to download or open.. function OpenFile() { window.open("D:/Games/poker.exe", 'FilePopUp', 'resizable=yes,scrollbars=1'); } If I give some other files in place of poker.exe, like .doc, .pdf, the code is working. but unable to download .exe files. Thanks in advance.

                S Offline
                S Offline
                Shorgov
                wrote on last edited by
                #7

                try different approach. Use this code in some button click event handler FileStream fs = null; string strContentType = "application/octet-stream"; string strPath = Server.MapPath("FILE_LOCATION_HERE") + "\\"; String strFileName = "FILE_NAME_HERE"; if (File.Exists(strPath + strFileName)) { byte[] bytBytes = new byte[fs.Length]; fs = File.Open(strPath + strFileName, FileMode.Open); fs.Read(bytBytes, 0, (int)fs.Length); fs.Close(); Response.AddHeader("Content-disposition", "attachment; filename=" + strFileName); Response.ContentType = strContentType; Response.BinaryWrite(bytBytes); Response.End(); }

                Strahil Shorgov

                N 1 Reply Last reply
                0
                • S Shorgov

                  try different approach. Use this code in some button click event handler FileStream fs = null; string strContentType = "application/octet-stream"; string strPath = Server.MapPath("FILE_LOCATION_HERE") + "\\"; String strFileName = "FILE_NAME_HERE"; if (File.Exists(strPath + strFileName)) { byte[] bytBytes = new byte[fs.Length]; fs = File.Open(strPath + strFileName, FileMode.Open); fs.Read(bytBytes, 0, (int)fs.Length); fs.Close(); Response.AddHeader("Content-disposition", "attachment; filename=" + strFileName); Response.ContentType = strContentType; Response.BinaryWrite(bytBytes); Response.End(); }

                  Strahil Shorgov

                  N Offline
                  N Offline
                  NarVish
                  wrote on last edited by
                  #8

                  Thanks alot Strahil Shorgov!!

                  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