Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and theā€¦
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to take different types of Oracle backups using RMAN.

751 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