Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-10-31
13
Medium Priority
?
3,914 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
11 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

783 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