Solved

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

Posted on 2008-10-31
13
3,279 Views
Last Modified: 2013-12-17
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.
0
Comment
Question by:ram27
  • 6
  • 4
13 Comments
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22850713
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
0
 

Author Comment

by:ram27
ID: 22851360
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.
0
 

Author Comment

by:ram27
ID: 22853267
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.
0
 
LVL 8

Expert Comment

by:mac-will
ID: 22854841
try something like this:

byte [] buff= (byte [])dr["DocumentContent"];  
MemoryStream ms = new MemoryStream(buff);
webBrowser1.DocumentStream = ms;
0
 
LVL 8

Expert Comment

by:mac-will
ID: 22854844
don't forget:

using System.IO;
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 8

Expert Comment

by:mac-will
ID: 22854852
sorry thry this instead:

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

Author Comment

by:ram27
ID: 22855891
i tried what you have mentioned. but it just loads the binary stream of data. it doen not show the actual contents
0
 
LVL 8

Expert Comment

by:mac-will
ID: 22857408
can you explain how the data is saved into the database?  is it saved as ascii LOB?
0
 
LVL 8

Expert Comment

by:mac-will
ID: 22857933
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

0
 

Author Comment

by:ram27
ID: 22864112
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.
0
 
LVL 8

Accepted Solution

by:
mac-will earned 500 total points
ID: 22867641
The Memory stream method should work you just need to set the DocumentType property to the correct MIME type.
eg
webBrowser1.DocumentType = "application/msword";

http://www.hansenb.pdx.edu/DMKB/dict/tutorials/mime_typ.php
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now