Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0
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...
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();
 
                                }
Posted 21-Nov-12 10:59am
Edited 21-Nov-12 11:20am
v2
Comments
Sergey Alexandrovich Kryukov at 21-Nov-12 16:31pm
   
In what line..?
--SA
Member 9291223 at 21-Nov-12 17:00pm
   
In this line:
Microsoft.Office.Interop.Word.ApplicationClass WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Sergey Alexandrovich Kryukov at 21-Nov-12 17:16pm
   
Wow! Are you sure? This is strange... Incompatible Office version or interop assembly..?
--SA
Member 9291223 at 21-Nov-12 17:58pm
   
But this works fine in local machine. Issues came after deployment

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Member 9291223 wrote:
But this works fine in local machine. Issues came after deployment.
OK, then it is no so strange. Office Interop works only when matching versions of Office an Office Interop assemblies are installed. (In your case, it could be just the Word-related part.) The fact the Interop Assembly was installed in your local GAC allowed you to build your product, and the fact that the matching version of Office is installed allowed you to run your application on a local machine. On the host where you deployed it, it could not be the case…
 
Logical, isn't it?
 
—SA
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 Maciej Los 270
3 DamithSL 225
4 Afzaal Ahmad Zeeshan 202
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100