powerpoint remotecontrol via Office/PowerPoint Object Library (c#)

B

bonk

Hello,
I am using Office/Powerpoint Object Library 9.0 to automate
PowerPoint-Presentations (see complete code below) via commandline
parameters I give to an app. Everything works as expected. I can open a ppt
I can close all ppt and I can jump to a certain slide etc.
There is only one option that still is not working. I want to be able to
constantly read from a file, that contains the number of the slide where to
jump to. In my app this is done via the "read" parameter followed by the
updatespeed followed by the file where to read the slidenumber from (see the
"read" case in the code).For some stange reason, when calling
view.GotoSlide(int.Parse(number),MsoTriState.msoTrue); in the timer
eventhandler nothing happens. I do not get an exception wirtten in the log;
the slide does not change. Also the frequnecy that eventhandler
(timer_Elapsed) gets excecuted is much lower than I set via commadline
argument. Also after approximatedly 24 times, the timer eventhandler
(timer_Elapsed) does not get sent at all anymore. Do you have any
suggestions/hints for me ?

Thank you for your help !

bonk



----------------------------------
---- Sourcecode of the complete Console application
---- to make it run you have to add the COM refernces of Office and
Powerpoint Object Library 9.0
----------------------------------

using System;
using Office;
using PowerPoint;
using System.IO;
using System.Timers;
using System.Threading;

namespace PPTRemote
{
class Class1
{
private static System.Timers.Timer timer = null;
private static StreamReader sr = null;
private static Application ppApp= null;
private static StreamWriter errorLog = null;
private static SlideShowView view = null;
[STAThread]
static int Main(string[] args)
{
errorLog = new StreamWriter("pptRemote.log",true);
if (args.Length >=1)
{
try
{
ppApp = new Application();
switch (args[0].ToLower())
{
case "read" :
if (args.Length>=3)
{
string filename = string.Empty;
for (int i=2;i<args.Length;i++)
{
filename+=args+" ";
}
filename = filename.Trim();
if (File.Exists(filename))
{
filename = Path.GetFullPath(filename);
FileStream fs = new FileStream
(filename,FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
sr = new StreamReader (fs);
int intervall = int.Parse(args[1]);
if (intervall<10)
{
errorLog.WriteLine("["+DateTime.Now.ToString("u")+"]");
errorLog.WriteLine("read : Wert für <Zeit> intervall
muss grösser als 10 sein");
errorLog.Flush();
return 0;
}
timer = new System.Timers.Timer ((double)intervall);
Console.WriteLine("Intervall: "+intervall);
timer.Elapsed+=new ElapsedEventHandler(timer_Elapsed);
timer.AutoReset = true;
view = ppApp.SlideShowWindows.Item(1).View;
timer.Start();
while (true)
{
Thread.Sleep(1000);
Console.Write(".");
}
}
else
{
errorLog.WriteLine("["+DateTime.Now.ToString("u")+"]");
errorLog.WriteLine("Datei "+filename+" existiert nicht");
errorLog.Flush();
}
}
return 0;
case "jump" :
if (args.Length >= 2)
ppApp.SlideShowWindows.Item(1).View.GotoSlide(int.Parse(args[1]),MsoTriState.msoTrue);
return 0;
case "last" :
return 0;
case "close" :
foreach (SlideShowWindow ssw in ppApp.SlideShowWindows)
{
ssw.Presentation.Close();
}
return 0;
case "open" :
if (args.Length>=2)
{
string filename = string.Empty;
for (int i=1;i<args.Length;i++)
{
filename+=args+" ";
}
filename = filename.Trim();
if (File.Exists(filename))
{
filename = Path.GetFullPath(filename);
Presentation ppt =
ppApp.Presentations.Open(filename,MsoTriState.msoTrue,MsoTriState.msoTrue,MsoTriState.msoFalse);
ppt.SlideShowSettings.Run();
}
else
{
errorLog.WriteLine("["+DateTime.Now.ToString("u")+"]");
errorLog.WriteLine("Datei "+filename+" existiert nicht");
errorLog.Flush();
}
}
return 0;
case "next" :
ppApp.SlideShowWindows.Item(1).View.Next();
return 0;
case "back" :
ppApp.SlideShowWindows.Item(1).View.Previous();
return 0;
case "help" :
case "/help" :
case "-help" :
case "-?" :
case "/?" :
case "?" :
Console.WriteLine("\r\nPPTRemote version 0.5 © 2005 by Robert
Ludewig\r\n\r\nDiese Anwendung kann eine Powerpointpresentation
fernsteuern\r\n\r\nBenutzung: \tPPTRemote Parameter1
[Parameter2]\r\n\r\nMögliche Parameter:\r\nclose \t\t- schließt alle derzeit
geöffneten Präsentationen\r\nopen <Datei> \t- öffnet und startet eine
Präsentation\r\njump <Nr> \t- springt zu der Foliennummer <Nr> in der
aktiven Präsentation\r\nnext \t\t- wechselt zu nächsten Folie in der aktiven
Präsentation\r\nback \t\t- wechselt zu vorherigen Folie inder aktiven
Präsentation\r\nlast \t\t- springt zu letzten Folie in der aktiven
Präsentation\r\nread <Zeit> <Datei>\t- Liest die anzuspringende Foliennummer
zyklish im abstand von <Zeit>Millisekunden aus der <Datei>");
return 0;
}
}
catch (Exception e)
{
errorLog.WriteLine("["+DateTime.Now.ToString("u")+"]");
errorLog.WriteLine(e);
errorLog.Flush();
return 1;
}
}
return 0;
}
private static void timer_Elapsed(object sender, ElapsedEventArgs e)
{
string number = string.Empty;
try
{
sr.BaseStream.Seek(0,SeekOrigin.Begin);
number = sr.ReadLine().Trim();
Console.WriteLine("Zeile gelesen: \"{0}\" Zahl:
{1}",number,int.Parse(number));
}
catch (Exception e1)
{
errorLog.WriteLine("["+DateTime.Now.ToString("u")+"]");
errorLog.WriteLine(e1);
errorLog.Flush();
}
try
{
//ppApp.SlideShowWindows.Item(1).View.GotoSlide(int.Parse(number),MsoTriState.msoTrue);
view.GotoSlide(int.Parse(number),MsoTriState.msoTrue);

}
catch (Exception e2)
{
errorLog.WriteLine("["+DateTime.Now.ToString("u")+"]");
errorLog.WriteLine(e2);
errorLog.Flush();
}
}
}
}
 
Top