文件下载 有提示的 你想下载或保存此文件吗?

下面贴上代码很简单 自己研究
private void FileDown(string strPath)
    {
        System.IO.FileInfo file 
= new System.IO.FileInfo(strPath);
        
if (file.Exists)
        {
            Response.Clear();
            Response.AddHeader(
"Content-Disposition""attachment; filename=" + HttpUtility.UrlEncode(file.FullName, System.Text.Encoding.UTF8));
            Response.AddHeader(
"Content-Length", file.Length.ToString());
            Response.ContentType 
= "application/octet-stream";
            Response.Filter.Close();
            Response.WriteFile(file.FullName);
            Response.End();
        }
        
else
        {
            ClientScript.RegisterStartupScript(GetType(), 
"""<script language='javascript'>alert('文件不存在!');</script>");
        }
    } 
posted @ 2008-07-15 09:39  AutumnWind  阅读(1082)  评论(0编辑  收藏  举报