Morpheusweb.it - Risorse per webmaster: script, ASP.NET, C#, Visual Basic .Net, tutorial, asp, javascript, css, php, html, java, ADO, VBScript, forms, frames, Active Server Pages, Dynamic HTML, database, gratis per webmaster e webdesigner

Force download - << C# VERSION >>


Force the download of a resource on the server


Private Sub DownloadFile(ByVal fname As String, ByVal forceDownload As Boolean)
  Dim path As Path
  Dim fullpath = path.GetFullPath(fname)
  Dim name = path.GetFileName(fullpath)
  Dim ext = path.GetExtension(fullpath)
  Dim type As String = ""
  If Not IsDBNull(ext) Then
    ext = LCase(ext)
  End If
  Select Case ext
    Case ".htm", ".html"
      type = "text/HTML"
    Case ".txt"
      type = "text/plain"
    Case ".doc", ".rtf"
      type = "Application/msword"
    Case ".csv", ".xls"
      type = "Application/x-msexcel"
    Case Else
      type = "text/plain"
  End Select
  If (forceDownload) Then
    Response.AppendHeader("content-disposition", _
      "attachment; filename=" + name)
  End If
  If type <> "" Then
    Response.ContentType = type
  End If
  Response.WriteFile(fullpath)
  Response.End()
End Sub



Download Code...


Print Page


 








Page top

risorse per webmaster