仰天一笑(Ansonxuyu),专业从事软件定制开发、Web软件开发,网站建设,网络推广,APP开发,微博应用开发,微信应用开发,电子商务开发,物联网开发等技术。
互联网8年风雨,愿在此交朋识友,交流心得,分享技术知识(策划/研发/运营/推广/合作)!QQ:943530498


仰天一笑

昨日不悔,今日勿失,明日莫忧! —徐羽

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

有个朋友问我下载弹出提示框的写法,具体如下:

出现提示框

string strFile="F:\\a.doc";//路径根据实际情况而定
if(!System.IO.File.Exists(strFile))
   {
    Response.Write("<script language='javascript'>alert('对不起,文件不存在!');</script>");
    return;
   }
   Response.Clear();
   Response.ClearHeaders();
   Response.Charset = "GB2312";
   Response.ContentEncoding =System.Text.Encoding.UTF8;
   Response.ContentType = "application/octet-stream";
   FileInfo fi=new FileInfo(strFile);
   Response.AddHeader("Content-Disposition","attachment;  filename="  +  HttpUtility.UrlEncode(fi.Name)) ;
   Response.AddHeader("Content-Length",fi.Length.ToString());
   byte[] tmpbyte=new byte[1024*8];
   FileStream fs=fi.OpenRead();
   int count;
   while((count=fs.Read(tmpbyte,0,tmpbyte.Length))>0)
   {
    Response.BinaryWrite(tmpbyte);
    Response.Flush();
   }
   fs.Close();  
   Response.End();

直接在浏览器中打开
   string strFile="F:\\a.doc";//路径根据实际情况而定
   Response.Clear();
   Response.ClearHeaders();
   Response.Charset = "GB2312";
   Response.ContentEncoding =System.Text.Encoding.UTF8;
   Response.ContentType = "application/msword";
   Response.WriteFile(strFile);

posted on 2006-12-18 19:18  仰天一笑  阅读(1887)  评论(1编辑  收藏  举报