character count of ms-word in asp.net
Hello ,
In my web Application ,I have to count character in MS-word application using Asp.net,
I have used stream like
FileStream fin;
string s;
char ch;
int count=0,i;
fin=new FileStream(@"d:\Test\test.doc",FileMode.Open);
StreamReader fread=new StreamReader(fin);
while((s=fread.ReadLine())!=null)
{
TextBox1.Text=s.ToString();
for(i=0;i<s.Length;i++)
{
ch=s[i];
if(ch!=0)
count++;
}
}
fread.Close();
ListBox1.Items.Add(count.ToString());
But this code is not working as it gives me total 1024 characters whatever characters be in actual document.
Can u give me any solution.
I have tried second way also by using com component of word as
object filePath="d:\\Test\\test.doc";
object readOnly=false;
object missing=System.Reflection.Missing.Value;
Word.ApplicationClass wa=new Word.ApplicationClass();
Word.Document cc=wa.Documents.Open(ref filePath,
ref missing,ref readOnly,ref missing,ref missing,ref missing,ref missing,
ref missing,ref missing,ref missing,ref missing,ref missing);
cc.Activate();
int coun=cc.Characters.Count;
cc.Close(ref missing,ref missing,ref missing);
wa.Application.Quit(ref missing,ref missing,ref missing);
but this too is giving errors of some macro.
If u have any solution or suggestion then plz help.
rajkumar sharma
__________________
-------------------
rajkumar sharma
http://www.apnasaathi.blogspot.com
|