using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.SessionState; using Business = SuperMap.RealEstate.HighWay.Running.Business; using HZQR.Common; namespace SuperMap.RealEstate.HighWay { /// /// Filehelper 的摘要说明 /// public class Filehelper : IHttpHandler { public void ProcessRequest(HttpContext context) { string action_type =Pub.Request("action_type") ; string action_data = Pub.Request("action_data"); //文件操作 action_data = "24".ToEncrypt(); string RetString = string.Empty; SuperMap.RealEstate.ServiceModel.Transaction _Transaction = new SuperMap.RealEstate.ServiceModel.Transaction(); switch (action_type) { #region 下载文件 case "downloadfile": Business.ATTACHMENT _ATTACHMENT = new Business.ATTACHMENT(_Transaction); _ATTACHMENT.AddSearchParameter("ATTACHMENT_ID", action_data.ToDecrypt()); if (_ATTACHMENT.Search()) { string uploadPath = HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile/") + "\\" + _ATTACHMENT.ATTACHMENT_NAME; if (!System.IO.File.Exists(uploadPath)) { context.Response.Write("error:服务器上该文件已被删除或不存在!"); return; } context.Response.Clear(); context.Response.Buffer = true; context.Response.Charset = "utf-8"; context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");//设置输出流为简体中文 context.Response.AddHeader("Content-Disposition", string.Format( "attachment; filename=" + _ATTACHMENT.ATTACHMENT_NAME, DateTime.Now.ToString("yyyyMMddHHmmssfff"))); context.Response.AddHeader("Content-length", System.IO.File.ReadAllBytes(uploadPath).Length.ToString()); //context.Response.BinaryWrite(System.IO.File.ReadAllBytes(uploadPath)); System.IO.FileInfo lFileInfo = new System.IO.FileInfo(uploadPath); context.Response.WriteFile(lFileInfo.FullName); context.Response.ContentType = "application/octet-stream";//设置输出文件类型为excel文件。 context.Response.Flush(); context.Response.End(); } break; #endregion case "DeleteFile"://删除运行库附件 RetString = Handler.CommonInterface.BusinessHelper.DeleteFile(_Transaction); break; case "deletefilebycode": Business.ATTACHMENT _ATTACHMENT2 = new Business.ATTACHMENT(_Transaction); _ATTACHMENT2.AddSearchParameter("ATTACHMENT_ID", action_data.ToDecrypt()); if (_ATTACHMENT2.Search()) { _ATTACHMENT2.Delete(); RetString = "1"; } break; } _Transaction.AutoCommit(); context.Response.ContentType = "text/plain"; context.Response.Write(RetString); context.Response.End(); } public bool IsReusable { get { return false; } } } }