Solved

How to show BLOB data in webBrowser control directly from memory stream

Posted on 2008-06-10
3
2,270 Views
Last Modified: 2008-08-16
Hi, I have a question about C#, Oracle and WebBrowser control.
I have Oracle database, table with BLOB field and I want to show its value
in webBrowser control in Windows Forms Application.
My task is to show data in webBrowser directly from memory stream.
Now I am using ShowBLOBs but is it posible to change ShowBLOBs
not to use temporary file and FileStream to show Blob field value
from database in webBrowser?


public override void ShowBLOBs()
{
  base.ShowBLOBs();
                  
  int Key = myBusinessObject.KeyValue;
  if (Key <= 0)
    return;

  object blob = myBusinessObject.readBlobFieldValue(BlobColumn);
  string tmpFile = @"c:\temp\doc_" + Key.ToString() + "." + BlobType;

  if (blob != null)
  {
    Byte[] byteBLOBData = blob as Byte[];

    if (byteBLOBData != null)
    try
    {
      MemoryStream ms = new MemoryStream(byteBLOBData);
      if (File.Exists(tmpFile))
        File.Delete(tmpFile);
      FileStream fs = new FileStream(tmpFile, FileMode.CreateNew);
                                    
      ms.WriteTo(fs);
      fs.Close();
      fs.Dispose();
      Application.DoEvents();

      ms.Close();
      ms.Dispose();

                  
      Application.DoEvents();
                                    
      //
     if (BlobType == "mht")
       webBrowser1.Url = new Uri(tmpFile); //for MHT
     else
       Process.Start(tmpFile);

    }
    catch (Exception ex)
    {
       MessageBox.Show("Error - showing file:" + Environment.NewLine + ex.Message);
    }
  }
}
            
0
Comment
Question by:ela1109
  • 2
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 21758507
The WebBrowser control exposes the DocumentStream, so you might be able to use that.
0
 

Author Comment

by:ela1109
ID: 21829522
I changed my code to

public override void ShowBLOBs()
{
  base.ShowBLOBs();
  int Key = myBusinessObject.KeyValue;
  if (Key <= 0)
      return;

  object blob = myBusinessObject.readBlobFieldValue(BlobColumn);
  string tmpFile = @"c:\temp\doc_" + Key.ToString() + "." + BlobType;

  if (blob != null)
  {
      Byte[] byteBLOBData = blob as Byte[];

      if (byteBLOBData != null)
      try
      {
        MemoryStream ms = new MemoryStream(byteBLOBData);
                                                                        
        //
        if (BlobType == "mht")
          webBrowser1.DocumentStream = ms; //for MHT
        else
          Process.Start(tmpFile);
                           }
        catch (Exception ex)
      {
        MessageBox.Show("Error - showing file:" + Environment.NewLine + ex.Message);
      }
  }
}
            
and it works BUT
because my Blob field content is Word document I see something like


MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_NextPart_01C80FF5.6C1133D0"
This document is a Single File Web Page, also known as a Web Archive file.
If you are seeing this message, your browser or editor doesn't support Web Archive files.
Please download a browser that supports Web Archive, such as Microsoft Internet Explorer.
------=_NextPart_01C80FF5.6C1133D0
Content-Location: file:///C:/2518D811/DOC_1003_1.htm
Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii"
<!--[if supportFields= ]> = FORMTEXT <![e= ndif]-->725000
 
 
<!--[if supportFi= elds]> FORMTEXT <![endif]-->2356<![endif]-->
 
How to show real document made in Microsoft Word 2003?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 21830045
And, that I wouldn't know.  :(
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creation date for a PDB 5 39
Migration from sql server to oracle 5 26
How to repeat the data 4 17
itextsharp with c# 3 8
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

860 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