I have been trying to read .ppt files from last 3 days. I searched a lot on internet and I came up with different source code snippets but nothing was perfect. And now i tried this code, and it is not printing "Check4" because of some unidentified problem in "Foreach" statement, and throwing an exception. Please guide me. I need it badly.
public static void ppt2txt (String source)
{
string fileName = System.IO.Path.GetFileNameWithoutExtension(source);
string filePath = System.IO.Path.GetDirectoryName(source);
Console.Write("Check1");
Application pa = new Microsoft.Office.Interop.PowerPoint.ApplicationClass ();
Microsoft.Office.Interop.PowerPoint.Presentation pp = pa.Presentations.Open (source,
Microsoft.Office.Core.MsoTriState.msoTrue,
Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoFalse);
Console.Write("Check2");
String pps = "";
Console.Write("Check3");
foreach (Microsoft.Office.Interop.PowerPoint.Slide slide in pp.Slides)
{
foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in slide.Shapes)
pps += shape.TextFrame.TextRange.Text.ToString ();
}
Console.Write("Check4");
Console.WriteLine(pps);
}
Thrown exception is
System.ArgumentException: The specified value is out of range. at Microsoft.Office.Interop.PowerPoint.TextFrame.get_TextRange() at KareneParser.Program.ppt2txt(String source) in c:\Users\Shahmeer\Desktop\New folder (2)\KareneParser\Program.cs:line 323 at KareneParser.Program.Main(String[] args) in c:\Users\Shahmeer\Desktop\New folder (2)\KareneParser\Program.cs:line 150
Line 323 on which exception is caught
pps += shape.TextFrame.TextRange.Text.ToString ();
Thanks in advance.