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. Regarding Binary data write

Regarding Binary data write

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasesql-serversysadminhelp
4 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.
  • U Offline
    U Offline
    Unknown Ajanabi
    wrote on last edited by
    #1

    Hi, I have trouble to write binary data stored in sql server databse to word document.when i run the program it write garbage value to document. how can i do it plz help My code is given below byte[] MyData = new byte[0]; da.Fill(ds, "myinages"); DataRow myRow; myRow = ds.Tables["myinages"].Rows[0]; MyData = (byte[])myRow["imgField"]; int ArraySize = new int(); ArraySize = MyData.GetUpperBound(0); string fileName=@"C:\Documents and Settings\Anurag_2\Desktop\anurag.doc"; Response.AppendHeader("Content-Type", "application/msword"); Response.AppendHeader("Content-disposition", "attachment; filename=" + fileName); Response.BinaryWrite(MyData); Response.Flush();

    no knowledge in .net

    M 1 Reply Last reply
    0
    • U Unknown Ajanabi

      Hi, I have trouble to write binary data stored in sql server databse to word document.when i run the program it write garbage value to document. how can i do it plz help My code is given below byte[] MyData = new byte[0]; da.Fill(ds, "myinages"); DataRow myRow; myRow = ds.Tables["myinages"].Rows[0]; MyData = (byte[])myRow["imgField"]; int ArraySize = new int(); ArraySize = MyData.GetUpperBound(0); string fileName=@"C:\Documents and Settings\Anurag_2\Desktop\anurag.doc"; Response.AppendHeader("Content-Type", "application/msword"); Response.AppendHeader("Content-disposition", "attachment; filename=" + fileName); Response.BinaryWrite(MyData); Response.Flush();

      no knowledge in .net

      M Offline
      M Offline
      michaelschmitt
      wrote on last edited by
      #2

      Hi, i'm assuming now that the byte[] you provide is valid. This is how i implemented "download-from-database" functionality, maybe it works for you, too.

      Response.ClearHeaders();
      Response.ClearContent();
      Response.ContentType = "Application/pdf"; // Modify this to word
      Response.AppendHeader("content-disposition", "attachment; filename=" +
      HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); // set fileName

      Response.AppendHeader("content-length", fileData.Length.ToString()); // fileData is a byte[]
      Response.OutputStream.Write(fileData, 0, fileData.Length);
      Response.End();

      U 1 Reply Last reply
      0
      • M michaelschmitt

        Hi, i'm assuming now that the byte[] you provide is valid. This is how i implemented "download-from-database" functionality, maybe it works for you, too.

        Response.ClearHeaders();
        Response.ClearContent();
        Response.ContentType = "Application/pdf"; // Modify this to word
        Response.AppendHeader("content-disposition", "attachment; filename=" +
        HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); // set fileName

        Response.AppendHeader("content-length", fileData.Length.ToString()); // fileData is a byte[]
        Response.OutputStream.Write(fileData, 0, fileData.Length);
        Response.End();

        U Offline
        U Offline
        Unknown Ajanabi
        wrote on last edited by
        #3

        Hi michaelschmitt, thanks for replying. I am still getting same error.i have define datatype of image in my table.while opening word file ,i recieve error that word can not start the converter mswrd632. plz provide me solution. thanks in advance.

        no knowledge in .net

        M 1 Reply Last reply
        0
        • U Unknown Ajanabi

          Hi michaelschmitt, thanks for replying. I am still getting same error.i have define datatype of image in my table.while opening word file ,i recieve error that word can not start the converter mswrd632. plz provide me solution. thanks in advance.

          no knowledge in .net

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

          Hi, i must admit, i'm a bit confused concerning your problem. You get binary data from your sql-server, which is actually an image? You want to write that to a doc file??? You use Response.[SomeWriteMethod] for that? There is some mixup, i'm sure. What your code basically does, is , it writes the binary data you retrieved from your sql-server (on server-side) to your responsestream (so someone can download it using the browser). There is no interaction with any file on your client-harddrive. You cannot directly write to a client file from your server-page. Maybe i'm just not understanding you correctly. Maybe someone else can help or you can describe a little bit more what youre trying to archive.

          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