title: Programmatically creating a MOSS publishing page
body: <p>I'm getting an error when creating a MOSS publishing page (this is a completely clean MOSS install, no site built into it yet). I'm using code which I've found on plenty of blogs, eg:</p>
  
  <pre><code>var pubWeb = PublishingWeb.GetPublishingWeb(Site.RootWeb);
  SPContentTypeId ctId = new SPContentTypeId(contentTypeId);
  var layouts = pubWeb.GetAvailablePageLayouts(ctId);
  var layout = layouts[0];
  
  var url = pageTitle.EndsWith(".aspx") ? pageTitle : pageTitle + ".aspx";
  var newPage = pubWeb.GetPublishingPages().Add(url, layout);
  </code></pre>
  
  <p>But when I do the <code>pubWeb.GetPublishingPages().Add</code> method call I get the following error:</p>
  
  <blockquote>
    <p>FormatException - Index (zero based) must be greater than or equal to zero and less than the size of the argument list.</p>
  </blockquote>
  
  <p>I've checked the following:</p>
  
  <ul>
  <li>ContentTypeId is valid</li>
  <li>layout has a value</li>
  <li>pubWeb.GetPublishingPages().Count == 1</li>
  </ul>
  
  <p>I can't seem to find anything useful via Google nor can I find anything in Reflector which could help.</p>