coolie
10-10-2008, 02:23 PM
I need to a read a word doc and then display all the content to a label. - this includes images.
Maybe that is just my error there, not possible to put content read from a word doc to a label, or pictures just can't go to labels. Anyway, i tried it with a rich textbox too and same issue, it won't print the images from the document to a rich text box.
Anyone able to help me do this! Again read a word doc and display everything! EVERYTHING.
I'm only able to display the text, the images are just squares.
Here is my method.
protected void OpenWordDoc(string filePath)
{
object nullobj = System.Reflection.Missing.Value;
object file = filePath;
Microsoft.Office.Interop.Word.ApplicationClass wordApp =
new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref file,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
try
{
lblContent.Visible = true;
lblContent.Text = "";
int i = 1;
foreach (Microsoft.Office.Interop.Word.Paragraph objParagraph in doc.Paragraphs)
{
try
{
lblContent.Text += doc.Paragraphs[i].Range.Text;
lblContent.Text += "<br />";
}
catch (Exception ex) { throw ex; } i++;
}
doc.Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
}
catch (Exception ee)
{
lblContent.Text = "Error: " + ee.Message;
doc.Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
}
}
Maybe that is just my error there, not possible to put content read from a word doc to a label, or pictures just can't go to labels. Anyway, i tried it with a rich textbox too and same issue, it won't print the images from the document to a rich text box.
Anyone able to help me do this! Again read a word doc and display everything! EVERYTHING.
I'm only able to display the text, the images are just squares.
Here is my method.
protected void OpenWordDoc(string filePath)
{
object nullobj = System.Reflection.Missing.Value;
object file = filePath;
Microsoft.Office.Interop.Word.ApplicationClass wordApp =
new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref file,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
try
{
lblContent.Visible = true;
lblContent.Text = "";
int i = 1;
foreach (Microsoft.Office.Interop.Word.Paragraph objParagraph in doc.Paragraphs)
{
try
{
lblContent.Text += doc.Paragraphs[i].Range.Text;
lblContent.Text += "<br />";
}
catch (Exception ex) { throw ex; } i++;
}
doc.Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
}
catch (Exception ee)
{
lblContent.Text = "Error: " + ee.Message;
doc.Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
}
}