Link to home
Start Free TrialLog in
Avatar of ram27
ram27

asked on

hOW to load BYTE [] data to the WebBrowser control in Windows Control

Hi

We have requirement to load "byte []" stream of data  and we have to load it on WebBrower control using C#,Vs2005..net framework 2.0. Could you please provide some thoughts on this.

Thanks,
Ram.
Avatar of Toms Edison
Toms Edison
Flag of India image

If the data in byte array is a string then convert it to string a and add to your control

check this link to know how to convert byte array to string

http://www.aspcode.net/Bytearray-to-string-and-string-to-bytearray.aspx
Avatar of ram27
ram27

ASKER

Once i convert Byte[] to string how can i load this into webbrowser control. My requirement is to load contents of the file( which wold have stored in database in biary format), i will be retreive this using stored proc, once i got the byte[] array how to to load this in webbrowser control.
Avatar of ram27

ASKER

I got an idea:
Want to do some thing like this:
1./retrieve it from database and assign to byte array
2. wtire to the webbrowser by using webBrowser1.DocumentStream.Write.
that i..e,

  byte [] buff= (byte [])dr["DocumentContent"];   this.webBrowser1.DocumentStream.Write(buff,0,buff.Length)

But  :webBrowser1.DocumentStream" is NUll how can we use write() method of documentstream.

Could you please suggest some solution on thi.
try something like this:

byte [] buff= (byte [])dr["DocumentContent"];  
MemoryStream ms = new MemoryStream(buff);
webBrowser1.DocumentStream = ms;
don't forget:

using System.IO;
sorry thry this instead:

using System.IO;
byte [] buff= (byte [])dr["DocumentContent"];  
webBrowser1.DocumentStream = new MemoryStream(buff);
Avatar of ram27

ASKER

i tried what you have mentioned. but it just loads the binary stream of data. it doen not show the actual contents
can you explain how the data is saved into the database?  is it saved as ascii LOB?
I did a simple test and both of these work for me:
String myHTML = "<html>simple test </html>";
byte[] myHTML_bytes = Encoding.Default.GetBytes(myHTML);
MemoryStream ms = new MemoryStream(myHTML_bytes);
webBrowser1.DocumentStream = ms;
 
OR
 
String myHTML = "<html>simple test </html>";
byte[] myHTML_bytes = Encoding.Default.GetBytes(myHTML);
webBrowser1.DocumentText = Encoding.Default.GetString(myHTML_bytes);

Open in new window

Avatar of ram27

ASKER

Thanks for your reply i am sending file contents as "Byte []"( byte array) and it will be saved in database as 'image'. Also file type also will be saved in Database, it could be any type like . ., application/msword,application/vnd.ms-excel,Application/pdf, video/wmv,image/bmp  etc..
Could you please suggest required changes.

Thanks,
Ram.
ASKER CERTIFIED SOLUTION
Avatar of mac-will
mac-will
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial