0

In my database i have a field whose datatype is BLOB.I use this field to store HTML formatted text (i.e texts enclosed in html tags etc). I want to fetch this binary data and render the contents in a WebBrowser control of C# windows form. I am using the code below but its just showing 'System.Byte[]' in the webbrowser control.

            if(rdr9e.Read())
            {
                byte[] byt = (byte[])rdr9e["q_r_desc"];
                MemoryStream ms = new MemoryStream();
                ms.Write(byt, 0, byt.Length);
                ms.Position = 0;
                webBrowser1.DocumentStream = ms;
            }

Here 'q_r_desc' is the field containing binary data.My question is how do i show binary data using webbrowser control.Any help with code would be highly appreciated.

gomesh munda
  • 838
  • 2
  • 14
  • 32

2 Answers2

1

You need to read your memorystream using a streamreader and the write out the results into a string / output...

How do you get a string from a MemoryStream?

Community
  • 1
  • 1
MaxOvrdrv
  • 1,780
  • 17
  • 32
  • good news friends, i have solved the above problem.The cause of the problem was that i have not been saving/inserting the data into blob field in a correct way – gomesh munda Dec 24 '15 at 09:41
1

You can convert the byte[] to MemorySteam and then assign it to DocumentStream property of your web browser control:

//Suppose you have an byte[] array that you load from somewhere, for exmple:
var array = Encoding.Unicode.GetBytes(@"<html><head></head><body>Hi dude!</body></html>");
this.webBrowser1.DocumentStream = new MemoryStream(array);

enter image description here

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • Reza thanks for the prompt reply once again. I tried your above code it works in a way, but the text its rendering is not what i had saved in the database. I mean to say that the characters being rendered are in some foreign language – gomesh munda Dec 23 '15 at 06:35
  • Well let me explain my requirement . I have a fully working web application made using PHP5 and MySql. In the website i have a WYSIWYG editor.Through this editor i save HTML text i.e. formatted text containing text and some image etc. into Blob field. Now i am necessitated to create an windows application which will MOMENTARILY connect to remote server and download those formatted HTML data and display them in WebBrowser control. – gomesh munda Dec 23 '15 at 06:41
  • Reza suppose if you are required to design such an application then what would be your approach? – gomesh munda Dec 23 '15 at 07:07
  • So it seems, mistakenly your data in database is stores as this string `System.Byte[]`. – Reza Aghaei Dec 23 '15 at 07:07
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/98778/discussion-between-user1448677-and-reza-aghaei). – gomesh munda Dec 23 '15 at 07:09