Regarding Binary data write
-
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
-
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
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 fileNameResponse.AppendHeader("content-length", fileData.Length.ToString()); // fileData is a byte[]
Response.OutputStream.Write(fileData, 0, fileData.Length);
Response.End(); -
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 fileNameResponse.AppendHeader("content-length", fileData.Length.ToString()); // fileData is a byte[]
Response.OutputStream.Write(fileData, 0, fileData.Length);
Response.End();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
-
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
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.