title: Converting a powerpoint file from .ppt -> .pptx by using a bitstream using c#.net 2008
body: <p>I'm trying to create and open a powerpoint by using binary data from a sql database by using linq.</p>
  
  <p><strong>A. First I'm reading it into a byte array and then creating the .ppt file.</strong></p>
  
  <pre><code>public bool createPresentation(string fileName, byte[] powerPoint)
      {
          DirectoryInfo di = new DirectoryInfo(downloadPath);
          if (!di.Exists)
              di.Create();
  
          fileName = string.Concat(downloadPath, fileName,".PPT");
          //Define a new instance of FileStream
          FileStream powerpointStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite);
         powerpointStream.Write(powerPoint, 0, powerPoint.Count());
         powerpointStream.Close();
  
          return True; 
      }
  </code></pre>
  
  <p><strong>B. Then I'm trying to open the .ppt file and save it as a .pptx file</strong></p>
  
  <pre><code>public bool convertPPTtoPPTX(string path)
      {
          string source = path;
          string destination = path.Replace("PPT", "PPTX");
  
          DirectoryInfo di = new DirectoryInfo(downloadPathPPTX);
          if (!di.Exists)
              di.Create();
  
          PowerPoint.Application app = new PowerPoint.Application();//Line Y
  
          PowerPoint.Presentation pptx = app.Presentations.Open(source, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoFalse);//Line Z
          pptx.SaveAs(destination, PowerPoint.PpSaveAsFileType.ppSaveAsDefault);
          pptx.Close();
          app.Quit();
  
         return true;
      }
  </code></pre>
  
  <p><strong>C. Finally I'm trying to read the .pptx file into a byte array inorder to update the db through linq.</strong></p>
  
  <pre><code>    public byte[] convertToBinary(string source)
      {
          byte[] binary = File.ReadAllBytes(source);
          return binary;
      }
  </code></pre>
  
  <p><strong>E. This is how i obtain the binary data through linq-sql</strong></p>
  
  <pre><code>public List&lt;Template&gt; getPPTFileBiniary(int ID)
      {
          var ppt = from p in db.paPresentationTemplates
                    where p.ID==ID
                    select new Template { pptFile = p.PPTFile.ToArray() };
  
          return ppt.ToList();
      }
  </code></pre>
  
  <p><strong>F. Template class used in E</strong></p>
  
  <pre><code>class Template
  {
      public int ID { get; set; }
      public string  FileName { get; set; }
      public Byte[] pptFile { get; set; }
  
      public Template()
      { 
  
      }
  
  }
  </code></pre>
  
  <p>I've got several issues regarding this.</p>
  
  <ol>
  <li>For the following byte stream, I get a error thrown, stating: "PowerPoint could not open the file." from <strong>part B Line Z</strong>. 
  byte data: "0x00000000000000000000"
  Why is that?</li>
  <li>For some runtime instances the following exception is thrown again from <strong>Part B Line Y</strong>.
  "Creating an instance of the COM component with CLSID {91493441-5A91-11CF-8700-00AA0060263B} from the IClassFactory failed due to the following error: 80010108". But when I debug using F11 key, this exception is not thrown. Can someone please explain this?</li>
  <li>Also for some instances when calling part B, an exception is thrown which states "the powerpoint file is being used by another program/application." When powerpoint is not even running in my taskmanager processes.</li>
  </ol>
  
  <p>Please help me to overcome these barriers.
  Thanks,
  Yasindu.</p>