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. Error while providing file download in webpage

Error while providing file download in webpage

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-netxml
5 Posts 2 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.
  • S Offline
    S Offline
    seee sharp
    wrote on last edited by
    #1

    I have to provide download of files in ASP.NET 2.0 I am using following lines of code. try { Byte [] bytes = this.ContentController.GetFileContents(filePath); Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=File" + _fileExtension); Response.AddHeader("Content-Length", bytes.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.Buffer = true; Response.BinaryWrite(bytes); Response.Flush(); } catch(FileNotFoundException fnfe) { this.ShowErrorMessage(this.GetErrorString(ResourceIdentifiers.DOCUMENT_FILE_NOT_FOUND_ERROR)); } catch(Exception ex) { this.ShowErrorMessage(this.GetErrorString(ResourceIdentifiers.DOCUMENT_UNEXPECTED_ERROR)); } Using above code, when one clicks on file link, a default download box of IE appears. If user clicks on Save, the file gets saved on disk and user can open that file. If user clicks on Open, it opens registered application with file type and says, file not found. Using same code I am able to open Word file but I cannot open Excel, PDF files. Note: My application used Master pages, UIP Application Blocks. The code written above is inside a user control which gets loaded on view (webform) dynamically based on configration(xml) file. Please can anyone suggest what could be going wrong in the piece of code because of which I am not able to open Excel/PDF files. Apprciate your help. Thanks and regards, Ashish

    T 1 Reply Last reply
    0
    • S seee sharp

      I have to provide download of files in ASP.NET 2.0 I am using following lines of code. try { Byte [] bytes = this.ContentController.GetFileContents(filePath); Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=File" + _fileExtension); Response.AddHeader("Content-Length", bytes.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.Buffer = true; Response.BinaryWrite(bytes); Response.Flush(); } catch(FileNotFoundException fnfe) { this.ShowErrorMessage(this.GetErrorString(ResourceIdentifiers.DOCUMENT_FILE_NOT_FOUND_ERROR)); } catch(Exception ex) { this.ShowErrorMessage(this.GetErrorString(ResourceIdentifiers.DOCUMENT_UNEXPECTED_ERROR)); } Using above code, when one clicks on file link, a default download box of IE appears. If user clicks on Save, the file gets saved on disk and user can open that file. If user clicks on Open, it opens registered application with file type and says, file not found. Using same code I am able to open Word file but I cannot open Excel, PDF files. Note: My application used Master pages, UIP Application Blocks. The code written above is inside a user control which gets loaded on view (webform) dynamically based on configration(xml) file. Please can anyone suggest what could be going wrong in the piece of code because of which I am not able to open Excel/PDF files. Apprciate your help. Thanks and regards, Ashish

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      Response.ContentType = "application/vnd.ms-excel" Response.ContentType = "application/pdf"

      how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

      S 1 Reply Last reply
      0
      • T ToddHileHoffer

        Response.ContentType = "application/vnd.ms-excel" Response.ContentType = "application/pdf"

        how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

        S Offline
        S Offline
        seee sharp
        wrote on last edited by
        #3

        ToddHileHoffer, thanks for your help. I am still the same problem. Could anything else you can think of to getrid of this problem

        - ashish

        T 1 Reply Last reply
        0
        • S seee sharp

          ToddHileHoffer, thanks for your help. I am still the same problem. Could anything else you can think of to getrid of this problem

          - ashish

          T Offline
          T Offline
          ToddHileHoffer
          wrote on last edited by
          #4

          VB.NEt code that works from my old application. ' The following code writes the pdf file to the Client’s browser. Response.ClearContent() Response.ClearHeaders() Response.ContentType = "application/pdf" Response.WriteFile(Fname) 'String location of the file Response.Flush() Response.Close() 'delete the exported file from disk System.IO.File.Delete(Fname)

          how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

          S 1 Reply Last reply
          0
          • T ToddHileHoffer

            VB.NEt code that works from my old application. ' The following code writes the pdf file to the Client’s browser. Response.ClearContent() Response.ClearHeaders() Response.ContentType = "application/pdf" Response.WriteFile(Fname) 'String location of the file Response.Flush() Response.Close() 'delete the exported file from disk System.IO.File.Delete(Fname)

            how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

            S Offline
            S Offline
            seee sharp
            wrote on last edited by
            #5

            Seems I get the problem when I use UIPAB. Otherwise the same code works fine. Any idea what UIPAB does different.

            - ashish

            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