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 - << VB.NET VERSION >>


Force the download of a resource on the server


private void Page_Load(object sender, System.EventArgs e)
{
  Response.ContentType = "Application/pdf";
  string FilePath = MapPath("acrobat.pdf");
  Response.WriteFile(FilePath);
  Response.End();
}

private void DownloadFile( string fname, bool forceDownload )
{
  string path = MapPath( fname );
  string name = Path.GetFileName( path );
  string ext = Path.GetExtension( path );
  string type = "";
  if ( ext != null )
  {
    switch( ext.ToLower() )
    {
      case ".htm":
      case ".html":
        type = "text/HTML";
        break;
      case ".txt":
        type = "text/plain";
        break;
      case ".doc":
      case ".rtf":
        type = "Application/msword";
        break;
    }
  }
  if ( forceDownload )
  {
    Response.AppendHeader( "content-disposition",
        "attachment; filename=" + name );
  }
  if ( type != "" )
    Response.ContentType = type;
  Response.WriteFile( path );
  Response.End();
}



Download Code...


Print Page


 


Page top

risorse per webmaster