I am trying to set the content type programmatically using an itemadding eventreceiver so that when the user adds a document to a library the content type is pre-selected. I have two content types: Project Document and Document. I determine through code which type to use and set the column values. My problem is that I can't get the content type to switch to Project Document. Here is my code:
SPContentTypeId ctId = properties.Web.ParentWeb.ContentTypes["Project Document"].Id;
properties.AfterProperties["Content Type ID"] = ctId;
properties.AfterProperties["Content Type"] = properties.Web.ParentWeb.ContentTypes[ctId].Name;
properties.AfterProperties["ProjectID"] = "example id";
properties.AfterProperties["Title"] = "random document";
properties.AfterProperties["ProjName"] = "My Project";
base.ItemAdding(properties);
When the properties form opens up the default content type (Document) is showing. When I switch to Project Document the values I added are there.
So my question is: How do I get it to change to the Project Document content type before the properties box opens?