RSS Forums RSS

Reading word file

Please support our C# advertiser: DiscountASP.NET – 3 Months Free on C# Web Hosting
Reply
Posts: 66
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Reading word file

  #1  
Jan 13th, 2009
How can I read the contents (separate paragraphs) of a .doc /.docx file in C#
AddThis Social Bookmark Button
Reply With Quote  
Posts: 1,867
Reputation: Ramy Mahrous has a spectacular aura about Ramy Mahrous has a spectacular aura about 
Solved Threads: 214
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Posting Virtuoso

Re: Reading word file

  #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  
Posts: 66
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

  #3  
Jan 14th, 2009
I have added the reference, but could you be more elaborative with the ApplicaitonClass usage?
Reply With Quote  
Posts: 1,867
Reputation: Ramy Mahrous has a spectacular aura about Ramy Mahrous has a spectacular aura about 
Solved Threads: 214
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Posting Virtuoso

Re: Reading word file

  #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  
Posts: 66
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

  #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  
Posts: 1,867
Reputation: Ramy Mahrous has a spectacular aura about Ramy Mahrous has a spectacular aura about 
Solved Threads: 214
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Posting Virtuoso

Re: Reading word file

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 993 | Replies: 5 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:04 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC