Reading word file

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Reading word file

 
0
  #1
Jan 14th, 2009
How can I read the contents (separate paragraphs) of a .doc /.docx file in C#
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Reading word file

 
0
  #2
Jan 14th, 2009
Very easy...
Project->Add Reference->COM
tab and look for the Microsoft Word X.x Object Library
Use ApplicationClass class. Enjoy...
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Re: Reading word file

 
0
  #3
Jan 14th, 2009
I have added the reference, but could you be more elaborative with the ApplicaitonClass usage?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Reading word file

 
0
  #4
Jan 14th, 2009
No, I need you to try using it, I could tell you some code and your problem been solved! but I need you to try to learn. Please try
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Re: Reading word file

 
0
  #5
Jan 15th, 2009
Is there a way I could run it in background. i.e. without opening the word file.

Have manage to read the contents but it one can certainly notice the opening and closing of the world doc

Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();

object fileNameO = fileName;//"c:\\sample.doc";
object objFalse = false;
object objTrue = true;
object missing = System.Reflection.Missing.Value;
object emptyData = string.Empty;

try
{
Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(ref fileNameO, ref objFalse, ref objTrue,
ref objFalse, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref objTrue,
ref missing, ref missing, ref missing, ref missing);

aDoc.ActiveWindow.Selection.WholeStory();
aDoc.ActiveWindow.Selection.Copy();


IDataObject data = System.Windows.Forms.Clipboard.GetDataObject();
String filetext = data.GetData(System.Windows.Forms.DataFormats.Text).ToString();
System.Windows.Forms.Clipboard.SetDataObject(string.Empty);
richTextBox1.Text = filetext;
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
finally
{
wordApp.Documents.Close(ref missing, ref missing, ref missing);
wordApp.Application.Quit(ref missing, ref missing, ref missing);
}
}

Originally Posted by RamyMahrous View Post
No, I need you to try using it, I could tell you some code and your problem been solved! but I need you to try to learn. Please try
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Reading word file

 
0
  #6
Jan 15th, 2009
Look .doc file is binary file I think you can't do that without word, but .docx is follow OOXML you can play with it.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC