title: Creating .pptx file with OpenXML
body: <p>I want to create a PowerPoint presentation based on a template in C#.
  I am using the <code>OpenXML 2.0 SDK</code>.</p>
  
  <p>My first step.</p>
  
  <p>I took my .pptx template, changed it in C# code and copied it in my project.</p>
  
  <ol>
  <li><p>I was able to create slides based on my templates.</p></li>
  <li><p>Now i have some placeholders in my template i want to replace.</p></li>
  </ol>
  
  <p>I found the following method, on the <a href="http://msdn.microsoft.com/de-de/library/dd469465%28v=office.12%29#CreateDocswithOpenXMLSDK_CreatingaPresentationReportBasedonData">msdn side</a></p>
  
  <pre><code>void SwapPlaceholderText(SlidePart slidePart, string placeholder, string value) 
  { 
     //Find and get all the placeholder text locations. 
     List&lt;Drawing.Text&gt; textList = slidePart.Slide.Descendants&lt;Drawing.Text&gt;().Where(t =&gt; t.Text.Equals(placeholder)).ToList(); 
     //Swap the placeholder text with the text from DB 
     foreach (Drawing.Text text in textList) text.Text = value; 
  }
  </code></pre>
  
  <p>But the size of the list is 0.
  Does this method call even searching in the right method of my template?
  The information of the placeholder i am searching for is in the following method of my template.</p>
  
  <pre><code>private void GenerateUserDefinedTagsPart5Content(UserDefinedTagsPart userDefinedTagsPart5)
  {
   ...
   Tag tag71 = new Tag(){ Name = "FIELD.CHAPTER.CONTENT", Val = "#header#" };
   Tag tag72 = new Tag(){ Name = "FIELD.CHAPTER.VALUE", Val = "#header#" };
   ... }
  </code></pre>
  
  <p>What i am doing wrong? and how do i need to modify the placeholder-method?</p>
  
  <p>Best regards!</p>
  
  <p><strong>EDIT :</strong> I found out some strange thing. I declared in my PowerPoint template a placeholder called "#header#" and in my program i was searching for "#header#" but after i ran the program once, the "#header#" in the PowerPoint file changed to "header" i don't know why but when i search now for "header" my list size is 1 and the header will be replaced.</p>
  
  <p>But after running my program and want to start the PowerPoint presentation, it says the data is corrupted. Maybe you can see some mistakes: </p>
  
  <p>This is my main method.</p>
  
  <pre><code>    Template template = new Template();
      template.CreatePackage("templatesource");
  
      PresentationDocument doc = PresentationDocument.Open("templatesource", true);
      PowerPoint powerPoint = new PowerPoint(doc, proj);
      powerPoint.AddNewSlides();
  </code></pre>
  
  <p>PowerPoint-class:</p>
  
  <pre><code>public void addSlides()
  {
      for (int i = 0; i &lt; proj.projects.Capacity; i++  )
      {
          Console.WriteLine("Slide number: " + i);
          AddNewSlide(_document.PresentationPart);
      }
      _document.PresentationPart.Presentation.Save();
  }
  
  private void AddNewSlide(PresentationPart parent)
  {
      if (_slideTemplate == null) return;
  
      var newSlidePart = parent.AddNewPart&lt;SlidePart&gt;("newSlide" + _slideId);
  
      newSlidePart.FeedData(_slideTemplate.GetStream(FileMode.Open));
      newSlidePart.AddPart(_slideTemplate.SlideLayoutPart, _slideTemplate.GetIdOfPart(_slideTemplate.SlideLayoutPart));
  
      SetPlaceholder(newSlidePart, "#header#", "My new header");
  
      newSlidePart.Slide.Save();
  
      SlideIdList listOfSlidesIDs = parent.Presentation.SlideIdList;
      uint maxSlideId = 1;
  
      foreach (SlideId slideId in listOfSlidesIDs.ChildElements)
      {
          if (slideId.Id &gt; maxSlideId) maxSlideId = slideId.Id;
      }
  
      SlideId newSlideId = new SlideId { Id = ++maxSlideId, RelationshipId = parent.GetIdOfPart(newSlidePart) };
      listOfSlidesIDs.Append(newSlideId);
  
      _slideId++;  
  }
  </code></pre>
  
  <p>Thanks for your help :)</p>