Chinaunix首页 | 论坛 | 博客
  • 博客访问: 783397
  • 博文数量: 738
  • 博客积分: 7000
  • 博客等级: 少将
  • 技术积分: 5000
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-12 09:00
文章分类

全部博文(738)

文章存档

2011年(1)

2008年(737)

我的朋友

分类:

2008-09-12 09:07:55

  ///   /// 附件。   ///   /// 文件名   /// 文件路径   public static void DownLoadFileAttachment(string fileName , string path)   {   if (System.IO.File.Exists(path))   {   try   {   fileName = fileName.Trim();   for (int i = 0 ; i < System.IO.Path.InvalidPathChars.Length ; i ++)   {   fileName = fileName.Trim().Replace(System.IO.Path.InvalidPathChars[i].ToString()
, string.Empty);   }   fileName = fileName.Replace(System.IO.Path.PathSeparator.ToString() , string.Empty);   int maxLength = 155;   int length = HttpUtility.UrlEncode(fileName).Length;   while (length > maxLength)   {   int index = fileName.LastIndexOf(".");   if (index > 0)   {   fileName = fileName.Substring(0 , index - 1) + fileName.Substring(index);   }   else   {   fileName = fileName.Substring(0 , fileName.Length - 1);   }   length = HttpUtility.UrlEncode(fileName).Length;   }   System.IO.FileInfo file = new System.IO.FileInfo(path);   HttpContext.Current.Response.Clear();   HttpContext.Current.Response.AppendHeader("Content-Disposition",
"attachment; filename=" + HttpUtility.UrlEncode(fileName));   HttpContext.Current.Response.AppendHeader("Content-Length", file.Length.ToString());   HttpContext.Current.Response.ContentType = "application/octet-stream";   HttpContext.Current.Response.WriteFile(file.FullName);   HttpContext.Current.Response.End();   }   catch   {   }   }   else   {   HttpContext.Current.Response.Clear();   DisplayNoFileMessage();   HttpContext.Current.Response.End();   }   }

--------------------next---------------------

阅读(471) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~