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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Opening a binary document from db is failing

Opening a binary document from db is failing

Scheduled Pinned Locked Moved C#
databasecsharpsql-serversysadminhelp
11 Posts 3 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 seeism

    Hi, I am downloading a binary document from sql server and depending upon my file extn it should either open doc txt or image.For txt it is working fine while for word it is saying"Word experience an error in opening the file".While for jpg image viewer is opening but no image is there What could be the reason I am using windows application in C#

    A Offline
    A Offline
    Abhinav S
    wrote on last edited by
    #2

    Looks like your file is not getting downloaded completely. Post some code here - maybe someone can help you.

    The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick - Silverlight *.XCP files

    S 1 Reply Last reply
    0
    • A Abhinav S

      Looks like your file is not getting downloaded completely. Post some code here - maybe someone can help you.

      The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick - Silverlight *.XCP files

      S Offline
      S Offline
      seeism
      wrote on last edited by
      #3

      if (dt.Rows.Count > 0) { result = (byte[])dt.Rows[0].ItemArray[0]; filetype = (String)dt.Rows[0].ItemArray[1]; } String new_FileName = Path.ChangeExtension(Path.GetTempFileName(),filetype); File.WriteAllBytes(new_FileName, result); System.Diagnostics.Process.Start(new_FileName); THis is my code i will get bytes in result array and filetype also.SO depending on that I am opening the file to display the data

      G 1 Reply Last reply
      0
      • S seeism

        if (dt.Rows.Count > 0) { result = (byte[])dt.Rows[0].ItemArray[0]; filetype = (String)dt.Rows[0].ItemArray[1]; } String new_FileName = Path.ChangeExtension(Path.GetTempFileName(),filetype); File.WriteAllBytes(new_FileName, result); System.Diagnostics.Process.Start(new_FileName); THis is my code i will get bytes in result array and filetype also.SO depending on that I am opening the file to display the data

        G Offline
        G Offline
        Goutam Patra
        wrote on last edited by
        #4

        In my case the same is working properly but I am using dt.rows(0)("FieldName") instead of Itemarray. May be there is problem while saving it into database.

        S 3 Replies Last reply
        0
        • G Goutam Patra

          In my case the same is working properly but I am using dt.rows(0)("FieldName") instead of Itemarray. May be there is problem while saving it into database.

          S Offline
          S Offline
          seeism
          wrote on last edited by
          #5

          I use coloumn name also .But same happening.

          1 Reply Last reply
          0
          • G Goutam Patra

            In my case the same is working properly but I am using dt.rows(0)("FieldName") instead of Itemarray. May be there is problem while saving it into database.

            S Offline
            S Offline
            seeism
            wrote on last edited by
            #6

            Hey , i found the solution.My data type that i put is binary so there is a limitation to the size.You have to put the type as image then size wont be a probs.So fix the solution.thanks for al the help; seeism

            1 Reply Last reply
            0
            • G Goutam Patra

              In my case the same is working properly but I am using dt.rows(0)("FieldName") instead of Itemarray. May be there is problem while saving it into database.

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

              Hi, Instead of opening the binary data from db in a file is it possible to store this in a file in some locations given by the user. Like if my binary file is a doc file i should store that file in some location say c:\file.doc. seeism

              G 1 Reply Last reply
              0
              • S seeism

                Hi, Instead of opening the binary data from db in a file is it possible to store this in a file in some locations given by the user. Like if my binary file is a doc file i should store that file in some location say c:\file.doc. seeism

                G Offline
                G Offline
                Goutam Patra
                wrote on last edited by
                #8

                What? you want to copy the file in a diff location? Just copy the file in a specified location using IO.File.Copy

                S 1 Reply Last reply
                0
                • G Goutam Patra

                  What? you want to copy the file in a diff location? Just copy the file in a specified location using IO.File.Copy

                  S Offline
                  S Offline
                  seeism
                  wrote on last edited by
                  #9

                  Hi, I got the file in binary format from db.Now i want to save this file in some location given by the user by a file save as dialog option without opening it. String new_FileName = Path.ChangeExtension(Path.GetTempFileName(), filetype); File.WriteAllBytes(new_FileName, result); FileDialog fldlg = new SaveFileDialog(); fldlg.InitialDirectory = "c:\\";// @":D\"; fldlg.Filter = "*.jpg|*.gif|*.txt|*.doc|*.pdf|*.htm"; fldlg.FileName = filename; This is my code.I did like this But file is not saving

                  G 1 Reply Last reply
                  0
                  • S seeism

                    Hi, I got the file in binary format from db.Now i want to save this file in some location given by the user by a file save as dialog option without opening it. String new_FileName = Path.ChangeExtension(Path.GetTempFileName(), filetype); File.WriteAllBytes(new_FileName, result); FileDialog fldlg = new SaveFileDialog(); fldlg.InitialDirectory = "c:\\";// @":D\"; fldlg.Filter = "*.jpg|*.gif|*.txt|*.doc|*.pdf|*.htm"; fldlg.FileName = filename; This is my code.I did like this But file is not saving

                    G Offline
                    G Offline
                    Goutam Patra
                    wrote on last edited by
                    #10

                    What exactly you are trying to do? SaveFileDialog doesnt saves anything. It only shows the dialog box. You need to use fldlg.ShowDialog to show dialog and ask user to select a filename. Then you need to copy the file into its new location specified by user using system.IO.File.Copy(new_FileName, fldlg.FileName) or sort of.

                    S 1 Reply Last reply
                    0
                    • G Goutam Patra

                      What exactly you are trying to do? SaveFileDialog doesnt saves anything. It only shows the dialog box. You need to use fldlg.ShowDialog to show dialog and ask user to select a filename. Then you need to copy the file into its new location specified by user using system.IO.File.Copy(new_FileName, fldlg.FileName) or sort of.

                      S Offline
                      S Offline
                      seeism
                      wrote on last edited by
                      #11

                      Thanks a lot.I didnt copy the code for showDialog.I was using some stream and all and it wasnt worked.I changed the code now using File.copy and it is working fine.thanks a lot

                      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