0

is there a way so i can count the words in a word file (all versions) in classic asp or asp.net?

what i need is to know how many words and if possible to make an array of word length and how many from each so words of 1,2,3 letters will get less attention from the code later.

i was thinking of using FSO or something like that but that won't work for docx

i can upload the file with aspupload or any other object if needed. if there is an object that can be bought that will upload and count words i don't have a problem purchasing it

thanks in advance

AnonJr
  • 2,759
  • 1
  • 26
  • 39
Y.G.J
  • 1,098
  • 5
  • 19
  • 44
  • Can use streamreader to read the file and use space as a seperator and new line character and increment the count with each space and new line. – Ankur Sep 02 '13 at 05:05

1 Answers1

3

You have several options -

  1. If you can have office installed on the server and don't require this to be an fast solution, you can try Word Interop. See Word count using Microsoft.Office.Interop.Word. A similar option is to have OpenOffice installed and work with that, never did that myself.
  2. You can use the IFilter interface (http://msdn.microsoft.com/en-us/library/ms691105(v=vs.85).aspx). Microsoft already implemented logic to take Word files and give you access to the inner text, so all you'll have to do is count the words. Look at the first answer here Are IFilters necessary to index full text documents using Lucene.NET and the link it provides or How to extract text from MS office documents in C#. You can also look at http://blogs.msdn.com/b/jasonz/archive/2009/08/31/sample-parsing-content-in-c-using-ifilter.aspx
  3. You can use 3rd party tools, I know there are some out there, but I'm not really familiar with any of them. For example see http://www.aspose.com/.net/word-component.aspx
  4. If you don't really need support for ALL word versions, then there are various ways to work with Word 2007+ files - for example - the official openXML or the open source docx

Option (2) seems like the way to go to me.

Community
  • 1
  • 1
Vadim
  • 2,847
  • 15
  • 18