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. Download PDF from MY SQL database in asp.net

Download PDF from MY SQL database in asp.net

Scheduled Pinned Locked Moved ASP.NET
databasecsharpasp-netmysql
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.
  • I Offline
    I Offline
    Imran Khan Pathan
    wrote on last edited by
    #1

    Hey. I have one table in MySql Database. I have two field. documentBinary LongBlob documentContentType varchar My code to download file.

    byte[] data = (byte[])Dt.Rows[0]["documentBinary"];
    // encoding.GetBytes(Dt.Rows[0]["documentBinary"].ToString());// (byte[])Dt.Rows[0]["documentBinary"].ToString();

                System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
                response.ClearHeaders();
                response.ClearContent();
                response.Clear();
                //response.AddHeader("Content-Type", Dt.Rows\[0\]\["documentContentType"\].ToString());
                response.ContentType = Dt.Rows\[0\]\["documentContentType"\].ToString();
                response.AppendHeader("Content-Disposition",
                    "attachment; filename=" + Dt.Rows\[0\]\["titel"\].ToString() + ".pdf; size=" + data.Length.ToString());
    
                response.BinaryWrite(data);
                response.Flush();
                response.End();
    

    When I download file,File is downloaded successfully but not open in pdf format. Please look at my code and tell me where I am going wrong. Thanks Imrankhan

    please don't forget to vote on the post that helped you.

    S 1 Reply Last reply
    0
    • I Imran Khan Pathan

      Hey. I have one table in MySql Database. I have two field. documentBinary LongBlob documentContentType varchar My code to download file.

      byte[] data = (byte[])Dt.Rows[0]["documentBinary"];
      // encoding.GetBytes(Dt.Rows[0]["documentBinary"].ToString());// (byte[])Dt.Rows[0]["documentBinary"].ToString();

                  System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
                  response.ClearHeaders();
                  response.ClearContent();
                  response.Clear();
                  //response.AddHeader("Content-Type", Dt.Rows\[0\]\["documentContentType"\].ToString());
                  response.ContentType = Dt.Rows\[0\]\["documentContentType"\].ToString();
                  response.AppendHeader("Content-Disposition",
                      "attachment; filename=" + Dt.Rows\[0\]\["titel"\].ToString() + ".pdf; size=" + data.Length.ToString());
      
                  response.BinaryWrite(data);
                  response.Flush();
                  response.End();
      

      When I download file,File is downloaded successfully but not open in pdf format. Please look at my code and tell me where I am going wrong. Thanks Imrankhan

      please don't forget to vote on the post that helped you.

      S Offline
      S Offline
      Sathesh Sakthivel
      wrote on last edited by
      #2

      Whether PDF is installed in your system.

      Sathesh. Blessed is the season which engages the whole world in a conspiracy of love.

      I 1 Reply Last reply
      0
      • S Sathesh Sakthivel

        Whether PDF is installed in your system.

        Sathesh. Blessed is the season which engages the whole world in a conspiracy of love.

        I Offline
        I Offline
        Imran Khan Pathan
        wrote on last edited by
        #3

        Yes. It is installed. When I open file it shows me that file is corrupted. Thanks Imrankhan

        please don't forget to vote on the post that helped you.

        S 1 Reply Last reply
        0
        • I Imran Khan Pathan

          Yes. It is installed. When I open file it shows me that file is corrupted. Thanks Imrankhan

          please don't forget to vote on the post that helped you.

          S Offline
          S Offline
          Sathesh Sakthivel
          wrote on last edited by
          #4

          Check by check points and find can u you able to retreive the data from MYSQL.

          Sathesh. Blessed is the season which engages the whole world in a conspiracy of love.

          I 1 Reply Last reply
          0
          • S Sathesh Sakthivel

            Check by check points and find can u you able to retreive the data from MYSQL.

            Sathesh. Blessed is the season which engages the whole world in a conspiracy of love.

            I Offline
            I Offline
            Imran Khan Pathan
            wrote on last edited by
            #5

            Sathesh Sakthivel wrote:

            Check by check points and find can u you able to retreive the data from MYSQL.

            Everything works file, file is created also, but does not open. It shows me that file is corrupted or not supported.

            please don't forget to vote on the post that helped you.

            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