title: Create a page programatically with C# in SharePoint 2007
body: <p>Not sure if this is asked, but searching hasn't quite yielded what I'm looking for. I have a page layout already, what I need to do is programmatically create a page in the Pages library. </p>
  
  <p>I'm fuzzy on the details, but somehow I think I will need to open the Layout, then stream it to a page and then save the page. I'm unsure how to go about this.</p>
  
  <p>The page is context sensitive so I think I'll begin with using SPSite and SPWeb to get access to the lists. </p>
  
  <p>What I'm unclear on is, how can I get the Layouts? I think I should be able to add a page somewhat like this:</p>
  
  <pre><code> SPWeb web = SPContext.Current.Site.OpenWeb();
  
  
                      SPList Pages = web.Lists["Pages"];
                      SPListItemCollection splc = Pages.Items;
  
  
                      foreach (SPListItem spli in splc)
                      {
                          if (spli.Name == "lmIntraTopicsArticle")
                          {
  
                          }
                      }
  
                      SPListItem sli = splc.Add();
                      Pages.Update();
                      SPFolder PagesFolder = Pages.RootFolder;
                      byte[] layoutContents = new byte[20];
                      SPFile myNewPage = PagesFolder.Files.Add(PagesFolder.Url + "/TopicWindowArchive.aspx", layoutContents);
                      web.Update();
  </code></pre>
  
  <p>Now I need to figure out how to add content from a layout. Update in a few if I figure it out.</p>
  
  <p>Thank you,</p>