64,849
社区成员
![](https://csdnimg.cn/release/cmsfe/public/img/topic.427195d5.png)
![](https://csdnimg.cn/release/cmsfe/public/img/me.40a70ab0.png)
![](https://csdnimg.cn/release/cmsfe/public/img/task.87b52881.png)
![](https://csdnimg.cn/release/cmsfe/public/img/share-circle.3e0b7822.png)
private void ProduceMhtFile(string URL,string FileName)
{
CDO.Message msg=new CDO.MessageClass();
msg.CreateMHTMLBody(URL,CDO.CdoMHTMLFlags.cdoSuppressAll,"","");
ADODB.Stream sw=msg.GetStream();
string urlPath = HttpContext.Current.Request.ApplicationPath + "/Temp/"; //虚拟目录
string physicPath = HttpContext.Current.Server.MapPath(urlPath); //物理地址
string strFileName=Guid.NewGuid()+".mht";
sw.SaveToFile(physicPath+strFileName,ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "mht";
HttpContext.Current.Response.WriteFile(urlPath+strFileName);
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(FileName)+"");
HttpContext.Current.Response.Charset ="GB2312";
HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.GetEncoding("GB2312");
HttpContext.Current.Response.ContentType ="text/mhtml";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
HttpContext.Current.Response.Flush();
System.IO.File.Delete(physicPath+strFileName);//删除临时文件
HttpContext.Current.Response.End();
}