Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-31
13
Medium Priority
?
3,791 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

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

Not sure which OpenStack Certification to get?

So you’ve realized you might want to get certified in OpenStack, but you’re not sure what the benefits might be or even which one you should take. You know there are several certification courses you can choose from, but how do you know which one is right for you?

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

718 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