Click here to Skip to main content
15,867,756 members

Error while doing page count

Member 9291223 asked:

Open original thread
Hi all

I have come up with a situation which gives me an error like this while doing word doc page count once I deployed my web application to the server.
Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
When I try to upload a word doc and do the page count the above error appears.Here the code that I am using for count doc pages...
C#
else if (extension == ".DOC" || extension == ".doc" || extension == ".docx")
                                {

                                    Microsoft.Office.Interop.Word.ApplicationClass WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
                                    

                                    // give any file name of your choice. 
                                    string tempath = numberofpage;
                                    RegexOptions options = RegexOptions.None;
                                    Regex regex = new Regex(@"[ ]{2,}", options);
                                    tempath = regex.Replace(tempath, @"");
                                    tempath = tempath.Replace(" \\", "\\");
                                    object fileName = tempath;
                                    object readOnly = false;
                                    object isVisible = true;

                                    //  the way to handle parameters you don't care about in .NET 
                                    object missing = System.Reflection.Missing.Value;
                                    object objDNS = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;

                                    //   Make word visible, so you can see what's happening 
                                    //WordApp.Visible = true; 
                                    //   Open the document that was chosen by the dialog 
                                    Microsoft.Office.Interop.Word.Document aDoc = WordApp.Documents.Open(ref fileName,
                                                            ref missing, ref readOnly, ref missing,
                                                            ref missing, ref missing, ref missing,
                                                            ref missing, ref missing, ref missing,
                                                                ref missing, ref isVisible);

                                    Microsoft.Office.Interop.Word.WdStatistic stat = Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages;
                                    count = aDoc.ComputeStatistics(stat, ref missing);

                                    WordApp.Quit(ref objDNS, ref missing, ref missing);

                                    aDoc = null;

                                    WordApp = null;

                                    GC.Collect();

                                }
Tags: C# (C# 3.0)

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900