Solved

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

Posted on 2008-10-31
13
3,598 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Stressed Out?

Watch some penguins on the livecam!

 
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
 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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 …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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