Software

[asp] Forzare il download di un documento da una pagina ASP

Quando un documento viene generato a run-time in una pagina ASP o ASP.NET per essere inviato al client, per esempio perchè viene recuperato da un database o da un’altra locazione, la proprietà ContentType dell’oggetto Response viene solitamente impostata con un valore che identifica il tipo del formato (tipo MIME). La proprietà menzionata corrisponde al parametro Content-Type dell’header della risposta HTTP.


'Documento PDF
Response.ContentType = "application/pdf"

'Archivio ZIP
Response.ContentType = "application/zip"

'Documento MS Word
Response.ContentType = "application/msword"

'Documento MS Excel
Response.ContentType = "application/vnd.ms-excel"

'Filmato ASF
Response.ContentType = "video/x-ms-asf"

'Filmato AVI
Response.ContentType = "video/avi"

'Filmato MPEG
Response.ContentType = "video/mpeg"

'Audio WAV
Response.ContentType = "audio/wav"

'Audio MP3
Response.ContentType = "audio/mpeg3"

'Immagine GIF
Response.ContentType = "image/gif"

'Immagine JPG
Response.ContentType = "image/jpeg"

'Formato binario generico
Response.ContentType = "application/octet-stream"

Quando un documento viene inviato al client, questo viene automaticamente aperto se il formato viene riconosciuto e associato ad un programma installato localmente.
Per evitare l’apertura automatica del documento, lasciando all’utente finale la scelta se aprire o salvare il file, occorre impostare anche il parametro Content-Disposition dell’header della risposta HTTP con il valore attachment, specificando inoltre il nome del file completo di estensione.

Response.AppendHeader("Content-Disposition", "attachment; filename=" & fileName)

Articolo tratto dal sito aspitalia.com

27/11/2008 Asp
No Comments

[tips] Google: i fattori più importanti che determinano il posizionamento

[howto] Accesso SSH con certificato via Putty

Lascia un commento

Devi essere connesso per inviare un commento.

Giugno 2025
L M M G V S D
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Giu    

Categorie

  • Access
  • Asp
  • Cyberoam
  • Dell
  • ESX / vmWare
  • Exchange
  • Exchange 2007
  • How-To
  • IIS
  • iPhone
  • Linux
  • Mac
  • Office 365
  • Outlook
  • plesk
  • Sophos XG
  • SQL Server
  • TeamSystem
  • Tips
  • Trend Micro
  • Vb.NET
  • VB6
  • Windows 10
  • Windows 7
  • Windows SBS
  • Windows Server
  • Windows Vista
  • Windows XP
  • WSUS

How-To

  • Configure SMTP O365 Migration Using TLS 1.2 For SQL Database Mail
  • Debian anti-spam and anti-virus e-mail gateway
  • How to install Small Business Server 2003 in an existing Active Directory domain
  • Sophos XG Firewall and Firebox Branch Office VPN Integration Guide
  • Squid, SquidGard, NTLM Authentication con Samba 3.x su Debian Sarge
  • Troubleshoot high-CPU-usage issues in SQL Server

Utili

  • Chip Grafici per portatili – Benchmark
  • Il blog su Microsoft Access
  • Processori per portatili – Benchmark
  • Sophos Wireless: Wi-Fi Fundamentals
  • Zentyal – Linux Small Business Server

Meta

  • Accedi
  • Feed dei contenuti
  • Feed dei commenti
  • WordPress.org
Proudly powered by WordPress | Theme: Neblue by NEThemes.