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

tablediff command line utility in SQL Server

Above tablediff utility is very useful for comparing tables.It is not only tells us which records / columns are different but can also generate a SQL script to update the second table to make it the same as the first table. You have to navigate to following path the use this utility SELECT 'C:\Program Files\Microsoft SQL Server\100\COM> Then type command ; tablediff –? Then it shows all the options as follows   But only limitation is you could compare one table at a time. Even though you can do some interesting work to overcome this. That is Just go to the SQL sever and type following command execute it. So it will generate the script for all the table. Then you can add it into .bat file. SELECT 'C:\Program Files\Microsoft SQL Server\100\COM>tablediff -sourceserver "SourceDBName" -sourcedatabase "T1" -sourcetable ' + '"' + name +'" ' + '-destinationserver "DestinationDBName" -destinationdataba...

Dead Code Problem

Problem Actually this problem occurred when i was doing integration two projects. [Phase1 and phase2 of a project] . Phase 2 is developed on top of the phase1. Parallel phase1 had changed lot . Mean time those were working on phase2 has commented existing phase 1 code without comments . Phase 1 and phase 2 merged with some conflicts. So we commented such places with the descriptive comment . After merged the result code base has merged those phase 2 commented parts. Also there was some of already dead code in phase 1. So it is difficult to understand weather this is actual dead code or commented one from phase 2. Mistake Had left dead dead code and missing comments . Lesson learned Normally developers leave dead code in their original code with the mind of future purpose. But this not a good habit to continue.As long as you use source control ,earlier code may exist. Problem will occur if you are not using such version control. In such a situation you can keep dead code with des...

Ship It Review -1

This books has been described Habits in interesting manner. Following story took from it and the story shows how we should go for a decision rather considering everybody doing it or becuse of we have already done it. Story: Did you hear the story of the woman who always cooked ham by cutting off and discarding a third of it first? When asked why, she said that was how her mother always cooked hams. When asked, her mother said that was how her mother had always cooked. They finally confronted Grandma, who admitted that when she was young, she didn’t have a pan big enough for an entire ham, so she always just cut the end off, and it became a habit.