mercoledì 13 giugno 2012

Caricamento di un oggetto nel browser

Un giorno mi sono imbattuto nel problema di visualizzare nel browser alcuni file con diverse estensioni.
Questi content-type di ritorno li ho sicuramente provati e vanno bene.
Ambiente MS VS 2005 .net 2.0 aspx IE
/// <summary>
/// extensionFile a 4 caratteri.
/// </summary>
/// <param name="extensionFile"></param>
/// <returns></returns>
public static string LoadContentType(string extensionFile)
{
 string contentType = "";
 switch (extensionFile)
 {           
  case ".vsd":
   contentType = "application/vnd.visio";
   break;
  case ".asf":
   contentType = "video/x-ms-asf";
   break;
  case ".txt":
   contentType = "text/plain";
   break;
  case ".avi":
   contentType = "video/avi";
   break;
  case ".doc":
   contentType = "application/msword";
   break;
  case ".zip":
   contentType = "application/zip";
   break;
  case ".xls":
   contentType = "application/vnd.ms-excel";
   break;
  case ".gif":
   contentType = "image/gif";
   break;
  case "jpeg":
   contentType = "image/jpeg";
   break;
  case ".jpg":
   contentType = "image/jpeg";
   break;
  case ".wav":
   contentType = "audio/wav";
   break;
  case ".mp3":
   contentType = "audio/mpeg3";
   break;
  case "mpeg":
   contentType = "video/mpeg";
   break;
  case ".rtf":
   contentType = "application/rtf";
   break;
  case "html":
   contentType = "text/html";
   break;
  case ".asp":
   contentType = "text/asp";
   break;
  case ".pdf":
   contentType = "application/pdf";
   break;
  case ".ppt":
   contentType = "application/vnd.ms-powerpoint";
   break;
  case ".mpp":
   contentType = "application/vnd.ms-project";
   break;
  default:
   contentType = "application/octet-stream";
   break;
 }
 return contentType;
}