I'm trying to create a new document in a SharePoint (WSS 3.0) document library with a specific content type. But the new document always has the default content type for the doc lib, not the custom one I specified :-(
I'm using SPFileCollection.Add to create the file, and using the properties Hashtable to pass the content type ID/name:
SPList list = web.Lists["Test Doc Lib"];
Hashtable properties = new Hashtable();
properties.Add("ContentType", "MyCustomContentType");
properties.Add("ContentTypeId", list.ContentTypes["MyCustomContentType"].Id.ToString());
list.RootFolder.Files.Add("Test File.html", Encoding.UTF8.GetBytes("test"), properties);
All the sample code I can find uses SPFileCollection.Add to initially create the file, then re-fetches the new SPListItem and sets the content type on this. I don't want to do this because it would cause both ItemAdding and ItemUpdating events to fire.