Read word Document using C# Interop and populate it into the DataGrid?
I want to read a Word document using C# Interop and populate it into the DataGrid.
I tried reading Word document by simple console program in c# it worked.
But I'm new to Asp.net and wants to know how to implement the program.
I'm able to create Word document but want to populate it to DATA grid.
string filePath = null;
OpenFileDialog file = new OpenFileDialog();
file.Title = "Word File";
file.InitialDirectory = "C:\\";
file.RestoreDirectory = true;
// execute if block when dialog result box click ok button
if (file.ShowDialog() == DialogResult.OK) {
// store selected file path
filePath = file.FileName.ToString();
}
try
{
// create word application
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.ApplicationClass();
// create object of missing value
object miss = System.Reflection.Missing.Value;
// create object of selected file path
object path = filePath;
// set file path mode
object readOnly = false;
// open document
Microsoft.Office.Interop.Word.Document docs = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss,ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
docs.ActiveWindow.Selection.WholeStory();
docs.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
//populate data into Datagridview?
docs.Close(ref miss, ref miss, ref miss);