943,929 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 5979
  • C# RSS
Jan 14th, 2009
0

Reading word file

Expand Post »
How can I read the contents (separate paragraphs) of a .doc /.docx file in C#
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
gallian99 is offline Offline
77 posts
since Jan 2009
Jan 14th, 2009
0

Re: Reading word file

Very easy...
Project->Add Reference->COM
tab and look for the Microsoft Word X.x Object Library
Use ApplicationClass class. Enjoy...
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Jan 14th, 2009
0

Re: Reading word file

I have added the reference, but could you be more elaborative with the ApplicaitonClass usage?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
gallian99 is offline Offline
77 posts
since Jan 2009
Jan 14th, 2009
0

Re: Reading word file

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
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Jan 15th, 2009
0

Re: Reading word file

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);
}
}

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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
gallian99 is offline Offline
77 posts
since Jan 2009
Jan 15th, 2009
0

Re: Reading word file

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.
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Jul 31st, 2010
0
Re: Reading word file
Hello,
read the contents (separate paragraphs) of a .doc /.docx file in C#.
there is two way to do this, first way is use office Interop, The office must be installed on the machine, Microsoft does not recommend using Office application in server-side scenarios.
Second way to use 3 party component, I used Spire.Doc.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
maryjok3698 is offline Offline
2 posts
since Jul 2010
Aug 2nd, 2010
0
Re: Reading word file
Was it really necessary to resurrect a thread over a year and a half old just to pitch a .net component?
Reputation Points: 512
Solved Threads: 246
Nearly a Posting Virtuoso
Ryshad is offline Offline
1,260 posts
since Aug 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Which Microsoft Visual edition is better?
Next Thread in C# Forum Timeline: Assign bitmap to image through constructor





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC