Programmatic document creation in umbraco

The umbraco API is extremely powerful and can easily be used to create content pages via code.  Recently I created an umbraco website where I needed to be able to take data from a genealogy file and create a page on the site for each individual in the file.

To create a document via code is fairly simple, first add the following two references to your code:

using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;

The code to create a document can be seen here:

// Get a reference to the docType 'Family' is my docType Alias
DocumentType dt = DocumentType.GetByAlias("Family");
    
// User 0 is the admin user
User author = umbraco.BusinessLogic.User.GetUser(0);

// Create a document with a name, a type, an umbraco user, and the ID of the 
// document's parent page. 
Document doc = Document.MakeNew("New Page Name", dt, author, 1376);
   
// Set document properties
doc.getProperty("pageTitle").Value = "";
doc.getProperty("metaKeywords").Value = "";
doc.getProperty("bodyText").Value = "";

// Prepare for publishing 
doc.Publish(author);

// Publish the document
umbraco.library.UpdateDocumentCache(doc.Id);
return doc.Id;

This code can then be put into a webservice and copied onto your umbraco site.  It can then be called from any application or system that needs to create content on your site.