1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
try
{
OpenFileDialog path = new OpenFileDialog();
//making an object for the OpenFileDialog
path.Title = "Tauqeer Sample";
path.InitialDirectory = @"c:\";
path.RestoreDirectory = true;
if (path.ShowDialog() == DialogResult.OK)
{
textBox1.Text = path.FileName.ToString();
source = path.FileName.ToString();
}
}
catch (Exception l)
{
MessageBox.Show(l.Message);
}
//*****************************************************
try
{
// Microsoft.Office.Interop.
Microsoft.Office.Interop.Word.Application wordObject = new Microsoft.Office.Interop.Word.Application();
object file = textBox1.Text; //this is the path
object nullobject = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document docs = wordObject.Documents.Open
(ref file, ref nullobject, ref nullobject, ref nullobject,
ref nullobject, ref nullobject, ref nullobject, ref nullobject,
ref nullobject, ref nullobject, ref nullobject, ref nullobject,
ref nullobject, ref nullobject, ref nullobject, ref nullobject
);
docs.ActiveWindow.Selection.WholeStory();
docs.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
textBox1.Text = data.GetData(DataFormats.Text).ToString();
docs.Close(ref nullobject, ref nullobject, ref nullobject);
}
catch (Exception j)
{
MessageBox.Show(j.Message);
}
} |
Partager