PowerPoint automation in Webbrowser Control

  • Thread starter Thread starter sam_sam80
  • Start date Start date
S

sam_sam80

Hi,

I did PowerPoint automation winthin Webbrowser Control. I can
open .ppt file and browse the slides.
My problem is when I have an other session of PPT open outside the
Webbrowser control I losse the control of my own file. Sometimes
when powerpnt process is still in the memory (caused by error in
closing PowerPoint) but not PowerPont is visible, I have the same
problem.


Here, a source code I use to do this.

//opning PPT file
object messing = System.Reflection.Missing.Value;
string filepath = "....."
this.axWebBrowser1.Navigate(filepath, ref messing, ref messing, ref
messing, ref messing);

// Get the powerpoint object
private void axWebBrowser1_DocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
opDisp = e.pDisp;
oDocument =
opDisp.GetType().InvokeMember("Document",BindingFlags.GetProperty,null,opDi­
sp,null);
oApplication =
opDisp.GetType().InvokeMember("Application",BindingFlags.GetProperty,null,o­
Document,null);

// I can't do automation from this object oApplication

Object oPresentation =
opDisp.GetType().InvokeMember("ActivePresentation",BindingFlags.GetProperty­,
null, oApplication, null);
Object oSlides =
opDisp.GetType().InvokeMember("Slides",BindingFlags.GetProperty, null,
oPresentation, null);
int slideCount = (int)
(opDisp.GetType().InvokeMember("Count",BindingFlags.GetProperty,
null,
oSlides, null));
Object oSlideShowWindow =
opDisp.GetType().InvokeMember("SlideShowWindow",BindingFlags.GetProperty,
null, oPresentation, null);
Object oSSWView =
opDisp.GetType().InvokeMember("View",BindingFlags.GetProperty, null,
oSlideShowWindow, null);


// PowerPoint Application object
PowerPoint.Application pptApplication =
(PowerPoint.Application)oApplication;

// Add Event handlers
pptApplication.SlideShowNextBuild +=new
PowerPoint.EApplication_SlideShowNextBuildEventHandler(pptApplication_Slide­
ShowNextBuild);
pptApplication.SlideShowNextSlide +=new
PowerPoint.EApplication_SlideShowNextSlideEventHandler(pptApplication_Slide­
ShowNextSlide);
pptApplication.SlideShowNextClick +=new
PowerPoint.EApplication_SlideShowNextClickEventHandler(pptApplication_Slide­
ShowNextClick);
}

Any help is very appreciate
Samir
 
What do you mean you lose control of your file?

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,

I did PowerPoint automation winthin Webbrowser Control. I can
open .ppt file and browse the slides.
My problem is when I have an other session of PPT open outside the
Webbrowser control I losse the control of my own file. Sometimes
when powerpnt process is still in the memory (caused by error in
closing PowerPoint) but not PowerPont is visible, I have the same
problem.


Here, a source code I use to do this.

//opning PPT file
object messing = System.Reflection.Missing.Value;
string filepath = "....."
this.axWebBrowser1.Navigate(filepath, ref messing, ref messing, ref
messing, ref messing);

// Get the powerpoint object
private void axWebBrowser1_DocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
opDisp = e.pDisp;
oDocument =
opDisp.GetType().InvokeMember("Document",BindingFlags.GetProperty,null,opDi­
sp,null);
oApplication =
opDisp.GetType().InvokeMember("Application",BindingFlags.GetProperty,null,o­
Document,null);

// I can't do automation from this object oApplication

Object oPresentation =
opDisp.GetType().InvokeMember("ActivePresentation",BindingFlags.GetProperty­,
null, oApplication, null);
Object oSlides =
opDisp.GetType().InvokeMember("Slides",BindingFlags.GetProperty, null,
oPresentation, null);
int slideCount = (int)
(opDisp.GetType().InvokeMember("Count",BindingFlags.GetProperty,
null,
oSlides, null));
Object oSlideShowWindow =
opDisp.GetType().InvokeMember("SlideShowWindow",BindingFlags.GetProperty,
null, oPresentation, null);
Object oSSWView =
opDisp.GetType().InvokeMember("View",BindingFlags.GetProperty, null,
oSlideShowWindow, null);


// PowerPoint Application object
PowerPoint.Application pptApplication =
(PowerPoint.Application)oApplication;

// Add Event handlers
pptApplication.SlideShowNextBuild +=new
PowerPoint.EApplication_SlideShowNextBuildEventHandler(pptApplication_Slide­
ShowNextBuild);
pptApplication.SlideShowNextSlide +=new
PowerPoint.EApplication_SlideShowNextSlideEventHandler(pptApplication_Slide­
ShowNextSlide);
pptApplication.SlideShowNextClick +=new
PowerPoint.EApplication_SlideShowNextClickEventHandler(pptApplication_Slide­
ShowNextClick);
}

Any help is very appreciate
Samir
 
Back
Top