title: How to insert new elements into an ssrs rdl object using c# and the rdl object model
body: <p>I am working on creating an rdl programmatically using the Object model that I have generated from the rdl schema. I start by loading an existing rdl template that contains a header footer and body as well as a datasource and dataset section into a file stream.</p>
  
  <pre><code>string docpath = "RDLTemplates/TemplateLetter.rdl";
  Report myReport = null;
  
  using (FileStream fs = new FileStream(docpath, FileMode.Open))
  {
      XmlSerializer serializer = new XmlSerializer(typeof(Report));
      myReport = (Report)serializer.Deserialize(fs);
  
  }
  return myReport;
  </code></pre>
  
  <p>I then pass this to an <code>InsertTablix()</code> method where I navigate through the stream to locate the body section</p>
  
  <pre><code> public Report InsertTablix(Report report, List&lt;string&gt; fieldnames)
          {
              int sectionindex = report.ItemsElementName.ToList().IndexOf(ItemsChoiceType118.ReportSections);
              if (sectionindex != -1)
              {
                  ReportSectionsType sections = (ReportSectionsType)report.Items[sectionindex];
                  if (sections.ReportSection.Length &gt; 0)
                  {  
                      int bodyIndex = sections.ReportSection[0].ItemsElementName.ToList().IndexOf(ItemsChoiceType117.Body);
                      if (bodyIndex != -1)
                      {
                          BodyType body = (BodyType)sections.ReportSection[0].Items[bodyIndex];
                          int tablixindex = body.Items.ToList().IndexOf(ItemsChoiceType80.Tablix);
  
                          if (tablixindex == -1)
                          {
                             //Here is where I would like to insert the tablix if it doesn't exist  
  
  
                          }
                      }
                  }
  
              }
  
              return report;
          } 
  </code></pre>
  
  <p>Where I am stuck is how to go about creating/inserting a tablix into this the body using the object model. I realize I can use XML to create report and I have tried this approach but I wanted to try to use the ObjectModel to help adhere and validate against the report schema.</p>
  
  <p>Can anyone provide some insight into how to add an element (tablix, textbox etc) into the body using this approach.</p>
  
  <p>-cheeers</p>