Displaying ad content from Respose.WriteFile()/ Response.ContentType

This is ugly, but the best way is to look at the file and set the content type as appropriate:

switch ( fileExtension )
{
    case "pdf": Response.ContentType = "application/pdf"; break; 
    case "swf": Response.ContentType = "application/x-shockwave-flash"; break; 

    case "gif": Response.ContentType = "image/gif"; break; 
    case "jpeg": Response.ContentType = "image/jpg"; break; 
    case "jpg": Response.ContentType = "image/jpg"; break; 
    case "png": Response.ContentType = "image/png"; break; 

    case "mp4": Response.ContentType = "video/mp4"; break; 
    case "mpeg": Response.ContentType = "video/mpeg"; break; 
    case "mov": Response.ContentType = "video/quicktime"; break; 
    case "wmv":
    case "avi": Response.ContentType = "video/x-ms-wmv"; break; 

    //and so on          

    default: Response.ContentType = "application/octet-stream"; break; 
}

Tags:

C#