title: Powerpoint to Text C# - Microsoft.Interop
body: <p>I have been trying to read <strong>.ppt</strong> 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 "<strong>Check4</strong>" because of some unidentified problem in "<strong>Foreach</strong>" statement, and throwing an exception. Please guide me. I need it badly. </p>
  
  <pre><code>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);
          }
  </code></pre>
  
  <p>Thrown exception is </p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>Line 323 on which exception is caught </p>
  
  <pre><code>pps += shape.TextFrame.TextRange.Text.ToString ();
  </code></pre>
  
  <p>Thanks in advance.</p>