Click here to Skip to main content
15,868,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am splitting the powerpoint presentation into multiple slides at that time this rpc error is coming , i already googled but not able to understand the cause of the problem. please help...!!
 <pre lang="c#">private void splitpptintomultipleslide(string path)
        {
            string realfilename = Path.GetFileNameWithoutExtension(path);
            Microsoft.Office.Interop.PowerPoint.Application pptapp = new Microsoft.Office.Interop.PowerPoint.Application();
            Microsoft.Office.Interop.PowerPoint.Presentation ppt1 = pptapp.Presentations.Open(path, Microsoft.Office.Core.MsoTriState.msoFalse,
            Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
            
            int j = ppt1.Slides.Count;
            x = 1;            
            try
            {              
                   string path1 = @"D:\practice\"; // or whatever 
                   if (!Directory.Exists(path1))
                   {
                       Directory.CreateDirectory(path1);
                       for (int i = 1; i <= j; i++)
                       {
                           string s = i.ToString();                           
                           string fullpath = path1 + realfilename + s + ".ppt";
                           string fullpathofimage = path1 + realfilename + s + ".png";
                           while (x == i)
                           {                               
                               <big>ppt1.Slides[x].Export(fullpath, "ppt");</big>
                                                    
                               <big>ppt1.Slides[x].Export(fullpathofimage, "png", 320, 620); </big>                                                           
                               x++;                               
                               ppt.Add(fullpath);                               
                              png.Add(fullpathofimage);                              
                           }
                       }
                   }
                   else
                   {
                       for (int i = 1; i <= j; i++)
                       {                          
                           string s = i.ToString();
                           string fullpath = path1 + realfilename + s + ".ppt";
                           string fullpathofimage = path1 + realfilename + s + ".png";
                           while (x == i)
                           {                               
                               <big>ppt1.Slides[x].Export(fullpath, "ppt"); </big>                                                                                      
                               <big>ppt1.Slides[x].Export(fullpathofimage, "png", 320, 620);</big>                                                              
                               x++;
                               ppt.Add(fullpath);                               
                              png.Add(fullpathofimage);                               
                           }
                       }
                   }                
            }
            finally
            {
                ppt1.Close();
                pptapp.Quit();
            }
        }
Posted
Updated 20-May-15 19:41pm
v3
Comments
Nathan Minier 4-Sep-14 11:20am    
I've seen some guidance that you need to allow WMI through your firewall if you're seeing this error, but unless you're using a network drive I'm not sure why this would be the case.

You might start by making sure your RPC service is running in the first place, Interop might need it.
nits23 5-Sep-14 0:34am    
#Nathan Minier thanks for reply :D

i checked that in my system RPC service is running , after that i am getting this error when i am splitting the presentation. so please give some direction how to resolve this issue.
Keerthi Koneru 20-May-15 12:58pm    
I could not solve it... I googled.. but did not get any solution
nits23 21-May-15 2:01am    
please check the below answer from nits23 may be it'll help you.
Keerthi Koneru 22-May-15 12:29pm    
Hi nits23, I am glad to see your reply..
I have applied both the techniques together of GC collection and Final release. In that case my ppt is getting closed before showing me a view, when i use them in finally block.

If i use them in catch block, the error persists.. can you suggest me please??

1 solution

First of all i used these code in two different system in one system had installed MS office 2013 installed and in other MS 2010 :-

in 2013 i am having this issue So i try with in other system with 2010 the issue was not there but my code was not in good shape so i refactored the code now my solution is working fine.

one thing to note:-
we are using MS Office appliaction all the MS Office are single threaded so we have to think wisely whethet to use it. Suppose if you are using it then you have to immediate release it when its work is done we can do this by two ways :-

1) :- First release all the minor objects to which you don't hold a reference within a named variable . You do this via a cal to GC.collect() and after that Call GC.WaitForPendingFinalizers() .

Note :- if you are using VSTO then You need to call this pair 2 times in order to get the Com objects to succefully release . otherwise 1 is enough.

2) :- Then explicitly release the objects which you hold via a named variable using a call to Marshal.FinalReleaseComObject() on each variable you have.

Remember to explicitly release all variables that you had use in com components . if you miss even one then your MS Office Application will hang.


example:-
GC.Collect();
GC.WaitForPendingFinalizers();

ppt1.Close();
Marshal.FinalReleaseComObject(ppt1);

pptApp.Quit();
Marshal.FinalReleaseComObject(pptApp);



Even this solution is working fine 2010 environment but its not working in 2013 environment so you have to see where to use it , if you guys have any better solution then please post it here .

this article is copied from internet , it was not mine .
 
Share this answer
 
Comments
Keerthi Koneru 21-May-15 9:23am    
Hi nits23, I am glad to see your reply..
I have applied both the techniques together of GC collection and Final release. In that case my ppt is getting closed before showing me a view, when i use them in finally block.

If i use them in catch block, the error persists.. can you suggest me please??

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



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