Is there any built in function that returns the content type based on the file extension?
If it's an uploaded file. You can store the contenttype in a column of the database for later use when you upload the file. There is a property named ContentType for HttpPostedFile class.