2025-03-27 15:05:14 +08:00

76 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using Business = SuperMap.RealEstate.HighWay.Storage.Business;
namespace HighWay.WebSite.Handler
{
/// <summary>
/// MainFrame 的摘要说明
/// </summary>
public class MainFrame_ajax : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
//文件操作
string action_type = HttpContext.Current.Request.Form["action_type"];
string action_data = HttpContext.Current.Request.Form["action_data"];
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();
_ATTACHMENT.ATTACHMENT_ID_Encrypt = action_data;
if (_ATTACHMENT.Select())
{
string uploadPath = HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile/") + "\\" + _ATTACHMENT.ATTACHMENT_NAME;
if (!System.IO.File.Exists(uploadPath))
{
context.Response.Write("error:服务器上该文件已被删除或不存在!");
return;
}
context.Response.Buffer = true;
context.Response.Clear();
context.Response.ContentType = "application/download";
string downFile = _ATTACHMENT.ATTACHMENT_NAME;//这里也可以随便取名
string EncodeFileName = HttpUtility.UrlEncode(downFile, System.Text.Encoding.UTF8);//防止中文出现乱码
context.Response.AddHeader("Content-Disposition", "attachment;filename=" + EncodeFileName + ";");
context.Response.BinaryWrite(System.IO.File.ReadAllBytes(uploadPath));//返回文件数据给客户端下载
_Transaction.AutoCommit();
context.Response.Flush();
context.Response.End();
}
break;
#endregion
case "deletefilebycode":
Business.ATTACHMENT _ATTACHMENT2 = new Business.ATTACHMENT();
_ATTACHMENT2.ATTACHMENT_ID_Encrypt = action_data;
if (_ATTACHMENT2.Select())
{
_ATTACHMENT2.Delete();
RetString = "1";
}
break;
}
context.Response.ContentType = "text/plain";
context.Response.Write(RetString);
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}