p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Professional (http://p2p.wrox.com/forumdisplay.php?f=57)
-   -   character count of ms-word in asp.net (http://p2p.wrox.com/showthread.php?t=42769)

sh.rajkumar May 19th, 2006 07:24 AM

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


All times are GMT -4. The time now is 07:40 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.