WebBrowse saves the database word,

Source: Internet
Author: User
Hi,
This is an extended question to http://www.experts-exchang E.com/Prog Ramming/La Nguages/ C _ Sharp/Q_23 183926. htm L.
I have Added A memorystream to a webbrowser:

Public WebBrowser createEmbeddedWord (Point point, MemoryStream memoryStream)
{
WebBrowser = new WebBrowser ();
WebBrowser. Location = point;
Size size = new Size (new Point (200,200 ));
WebBrowser. Size = size;

WebBrowser. DocumentStream = memoryStream;

Return webBrowser;

}

And when I run the program it displays the text in the webbrowser control, but you can't edit the text and it doesn't give the embedded word (word opened in the webbrowser) as if I did: // webBrowser. navigate (@ "C:\ Test \ MainTest1.doc");
To test it I have written a small function which takes a document and inserts it into a byte [] to simulate Binary Field on the server. Do I loose some formatting when I convert the document to byte [] since it doesn't open as a word document?

public class BLDocument{public byte[] OpenWord(){object missing = System.Reflection.Missing.Value;bool Visible = false;ApplicationClass WordApp = new ApplicationClass();WordApp.Visible = Visible;object filename = @"C:\MainTest1.doc";Document adoc = WordApp.Documents.Open(ref filename, ref missing, ref missing, ref missing, ref missing,ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,ref missing, ref missing, ref missing, ref missing);adoc.Activate();adoc.ActiveWindow.Selection.WholeStory();adoc.ActiveWindow.Selection.Copy();IDataObject temp = Clipboard.GetDataObject();string dataString = Convert.ToString(temp.GetData(DataFormats.UnicodeText));UTF8Encoding enc8 = new UTF8Encoding();byte[] dataArray = enc8.GetBytes(dataString);//MemoryStream memorystream = new MemoryStream(dataArray);return dataArray;}}、、
using System;            using System.Configuration;            using System.Data;            using System.Data.SqlClient;            using System.Windows.Forms;            using System.IO;            public class WordDocumentProcessor            {            private WebBrowser _webBrowser;            public WordDocumentProcessor(WebBrowser browser)            {            if (browser == null)            throw new NullReferenceException("Browser cannot be null");            _webBrowser = browser;            }            public void ShowInBrowser(int documentId)            {            byte[] buffer = this.GetDocument(documentId);            _webBrowser.DocumentStream.Write(buffer, 0, buffer.Length);            }            private byte[] GetDocument(int documentId)            {            string connectionString = ConfigurationManager.ConnectionStrings["MyDocuments"].ConnectionString;            using (SqlConnection connection = new SqlConnection(connectionString))            {            connection.Open();            using (SqlCommand command = new SqlCommand("spGetDocument"))            {            command.CommandType = CommandType.StoredProcedure;            command.Parameters.AddWithValue("@DocumentID", documentId);            return (byte[])command.ExecuteScalar();            }            }            }            }
http://blog.joycode.com/kaneboy/archive/2004/11/03/37889.aspx            

Open in New Window Select All

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.