Reputation:
I have a file Upload control to Browse the .odt document and read that document By using Button. Please can anyone suggest me to how to do this Please any one give any idea to me.
Thank you.
Upvotes: 1
Views: 1085
Reputation:
I recommend ODF.NET API for this task.
For example to read and count the words in an *.odt document, you can do it like this:
using System;
using System.Collections.Generic;
using Independentsoft.Office.Odf;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
int wordCount = 0;
string[] separator = new string[] { " " };
TextDocument doc = new TextDocument("c:\\test\\input.odt");
IList<Text> texts = doc.GetTexts();
for (int i = 0; i < texts.Count; i++)
{
string[] words = texts[i].Value.Split(separator, StringSplitOptions.RemoveEmptyEntries);
wordCount += words.Length;
}
IList<Paragraph> paragraphs = doc.GetParagraphs();
int emptyParagraphCount = 0;
for (int j = 0; j < paragraphs.Count; j++)
{
if(paragraphs[j].Content.Count == 0)
{
emptyParagraphCount++;
}
}
Console.WriteLine("Paragraphs=" + paragraphs.Count);
Console.WriteLine("Empty paragraphs=" + emptyParagraphCount);
Console.WriteLine("Words=" + wordCount);
Console.Read();
}
}
}
For more examples, please check these tutorials.
Upvotes: 1