zoukankan      html  css  js  c++  java
  • 文件下载实例

     1using System;
     2using System.Collections;
     3using System.ComponentModel;
     4using System.Data;
     5using System.Drawing;
     6using System.Web;
     7using System.Web.SessionState;
     8using System.Web.UI;
     9using System.Web.UI.WebControls;
    10using System.Web.UI.HtmlControls;
    11using System.IO;
    12
    13namespace UDS.SubModule.UnitiveDocument.Mail
    14{
    15    /// <summary>
    16    /// Download 的摘要说明。
    17    /// </summary>

    18    public class Download : System.Web.UI.Page
    19    {
    20        private void Page_Load(object sender, System.EventArgs e)
    21        {
    22            string destFileName = Request.QueryString["destFileName"]!=null?Request.QueryString["destFileName"]:"";
    23            destFileName = Server.MapPath(".")+destFileName;
    24            destFileName = Server.UrlDecode(destFileName);
    25            if(File.Exists(destFileName))
    26            {
    27                FileInfo fi = new FileInfo(destFileName);
    28                Response.Clear();
    29                Response.ClearHeaders();
    30                Response.Buffer = false;
    31                
    32                Response.AppendHeader("Content-Disposition","attachment;filename=" +HttpUtility.UrlEncode(Path.GetFileName(destFileName),System.Text.Encoding.Default));
    33                Response.AppendHeader("Content-Length",fi.Length.ToString());
    34                Response.ContentType="application/octet-stream";
    35                Response.WriteFile(destFileName);
    36                Response.Flush();
    37                Response.End();
    38            }

    39            else
    40            {
    41                Response.Write("<script langauge=javascript>alert('文件不存在!');history.go(-1);</script>");
    42                Response.End();
    43            }

    44        }

    45
    46        Web Form Designer generated code
    65    }

    66}

    67


    from:http://www.cnblogs.com/sapphire/archive/2005/11/07/271038.html
  • 相关阅读:
    Shell学习(四)Shell运算符
    Shell学习(三)Shell参数传递
    Shell学习(二)Shell变量
    Shell学习(一)认识Shell
    JVM学习(四)JVM调优
    JVM学习(三)JVM垃圾回收
    JVM学习(二)JVM加载类
    JVM学习(一)什么是JVM
    Python学习————包
    Python学习————模块
  • 原文地址:https://www.cnblogs.com/yiki/p/768701.html
Copyright © 2011-2022 走看看