Skip to main content

Research

Last week i play with COM object in dot net.That is very cool.
Using COM objects you can read the word document.By doing following thing you can achieve it.


Steps you should follow;
Add a COM reference to the project by right clicking in
the solution explorer on References->Add Reference. Click on the COM
tab and look for the Microsoft Word 9.0/
Microsoft Word 11.0/ Microsoft Word 12.0 Object Library. Click Select and OK.
In here the object library version depends on your MS.office package what you have installed in your machine .example: If it s Office 2007 the Microsoft Word 12.0 Object Library
<--------Source Code-------------->
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using Word = Microsoft.Office.Interop.Word;



public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnSubmit_Click(object sender, EventArgs e)
{

object missing = System.Reflection.Missing.Value;
Word.ApplicationClass wordApp = new Word.ApplicationClass();

// Input box is used to get the path of the file which has to be
//uploaded into textbox.

string filePath = filePath.Text;

object file = filePath;


object nullobj = System.Reflection.Missing.Value;

// here on Document.Open there should be 16 arg.

Word.Document doc = 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);



Word.Document doc1 = wordApp.ActiveDocument;

string m_Content = doc1.Content.Text;

// the content is stored into the textbox.
txtDisplay.Text = m_Content;

doc.Close(ref nullobj, ref nullobj, ref nullobj);
}
}
<----------------Source code -------->


Enjoy and play with COM objects.

Comments

Popular posts from this blog

MySQL Stored Procedure Error

In our project we had many many stored procedures and many parameters passes to those sps. But in only one sp it gives error message something like this; "Incorrect number of arguments for PROCEDURE sproc_t_l_Contract_Select_BySearchCriteria; expected 3, got 2” Work long time on this sp but coudnt find it. So i tried to write it again from the begining. In this time it was work perfectly.This problem occurs because of the space between data type and its length. Ex. pName varchar(50) - working pName varchar (50) - Not working But it does not mention syntax error or something.So this error message make us vulnerable.

The transaction is in doubt

Sometimes you may get this error when you use transaction scope . The transaction is in doubt I also got this error recently and able to find the reason for it. That is because of the some of the readers had not properly disposed. Actually in this case you can use Using keyword to overcome this. Exception : System.Transactions.TransactionInDoubtException was unhandled by user code Message="The transaction is in doubt." Solution : using (reader) { }

Appreciation

Today I got this touching email: One young academically excellent person went to apply for a managerial position in a big company. He passed the first interview, the director did the last interview, made the last decision. The director discovered from the CV,  that the youth's academic result is excellent all the way, from the secondary school until the postgraduate research, never has a year he did not score. The director asked, "Did you obtain any scholarship in school?" and the youth answered "none". The director asked, " Is it your father pay for your school fees?" the youth answered, my father passed away when I was one year old, it is my mother who paid for my school fees. The director asked, " Where did your mother worked?" the youth answered, my mother worked as cloth cleaner. The director requested the youth to show his hand, the youth showed a pair of hand that is smooth and perfect to the ...