If there are multiple content types associated to a document library and you don’t want to automatically upload to the default one, this is how to upload into a specific content type. This associates the metadata, content and content type in one action: (This was used to convert just under 1 million documents into SharePoint across multiple content types in multiple document libraries in multiple site collections)
‘ Open a filestream
fStream = File.OpenRead(“FileLocation”)
contents = New Byte(fStream.Length – 1) {}
fStream.Read(contents, 0, CInt(fStream.Length))
fStream.Close()
‘ Add any metadata needed and define the content type of the file.
documentMetadata = New Hashtable() From { _
{“Content_Type_ColumnName1”, valueOfColumn1}, _
{“Content_Type_ColumnName2”, valueOfColumn2}, _
{“Content_Type_ColumnName3”, valueOfColumn3}, _
{“Content_Type_ColumnName4”, valueOfColumn4}, _
{“ContentTypeId”, contentTypeID} _
}
‘ Add the file to the SPFileCollection
currentFile = files.Add(urlOfFile, contents, documentMetadata, True)
where files is the Microsoft.SharePoint.SPFileCollection for the document library.