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

x
?
Solved

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

Posted on 2008-06-10
3
Medium Priority
?
2,389 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 1500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
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 explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
Suggested Courses

876 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