Solved

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

Posted on 2008-10-31
13
3,330 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

930 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

13 Experts available now in Live!

Get 1:1 Help Now