Solved

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

Posted on 2008-06-10
3
2,220 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

705 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

16 Experts available now in Live!

Get 1:1 Help Now