- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
using System;
using System.Web;
using MaxPro;
namespace HandlerFile
{
public class FileHttpHandler : IHttpHandler
{
// Переопределяем метод ProcessRequest.
public void ProcessRequest(HttpContext context)
{
//var
Byte[] oImg;
Int32 iId=0;
Int32 iRemInt=0;
//var Zap
Int32 iNum=0;
Exception oErr;
Object[,] oZap=new Object[0,0];
//end var
if(All.IsInteger(context.Request.QueryString["iId"]))
{
iId=Convert.ToInt32(context.Request.QueryString["iId"]);
iNum=Ow.iZap1i("OneWindow.Procedure173","@iId",iId,out oZap,out oErr);
}
else if(All.IsInteger(context.Request.QueryString["iRemInt"]))
{
iId=Convert.ToInt32(context.Request.QueryString["iRemInt"]);
iNum=Ow.iZap1i("OneWindow.Procedure174","@iRemInt",iRemInt,out oZap,out oErr);
}
if(iNum>0)
{
oImg=(Byte[])oZap[0,0];
//генерация бинарного потока
/* Возможно пригодится, хотя ясности нет зачем,
* но когда ie сбоит и не открывает файл, то это помогает, особенно ClearHeaders
* Response.ClearContent()
* Response.ClearHeaders()
*///
context.Response.ContentEncoding=System.Text.Encoding.GetEncoding("UTF-8");
context.Response.Charset="UTF-8";
context.Request.ContentEncoding=System.Text.Encoding.UTF8;
switch (Convert.ToString(oZap[2,0]))
{
case "gif":
context.Response.ContentType="image/GIF";
context.Response.AddHeader("Content-Disposition","filename="+Convert.ToString(oZap[1,0]));
break;
case "jpg":
context.Response.ContentType="image/JPEG";
context.Response.AddHeader("Content-Disposition","filename="+Convert.ToString(oZap[1,0]));
break;
case "jpeg":
context.Response.ContentType="image/JPEG";
context.Response.AddHeader("Content-Disposition","filename="+Convert.ToString(oZap[1,0]));
break;
case "bmp":
context.Response.ContentType="image/BMP";
context.Response.AddHeader("Content-Disposition","filename="+Convert.ToString(oZap[1,0]));
break;
case "png":
context.Response.ContentType="image/PNG";
context.Response.AddHeader("Content-Disposition","filename="+Convert.ToString(oZap[1,0]));
break;
case "txt":
context.Response.ContentType="text/plain";
context.Response.AddHeader("Content-Disposition","filename="+Convert.ToString(oZap[1,0]));
break;
case "htm":
context.Response.ContentType="text/HTML";
context.Response.AddHeader("Content-Disposition","filename="+Convert.ToString(oZap[1,0]));
break;
case "html":
context.Response.ContentType="text/HTML";
context.Response.AddHeader("Content-Disposition","filename="+Convert.ToString(oZap[1,0]));
break;
case "xls":
context.Response.ContentType="application/vnd.ms-excel";
context.Response.AddHeader("Content-Disposition","attachment; filename="+Convert.ToString(oZap[1,0]));
break;
case "doc":
context.Response.ContentType="application/msword";
context.Response.AddHeader("Content-Disposition","attachment; filename="+Convert.ToString(oZap[1,0]));
break;
case "dot":
context.Response.ContentType="application/msword";
context.Response.AddHeader("Content-Disposition","attachment; filename="+Convert.ToString(oZap[1,0]));
break;
case "ppt":
context.Response.ContentType="application/vnd.ms-powerpoint";
context.Response.AddHeader("Content-Disposition","attachment; filename="+Convert.ToString(oZap[1,0]));
break;
default:
context.Response.AddHeader("Content-Disposition","attachment; filename="+Convert.ToString(oZap[1,0]));
break;
}
context.Response.OutputStream.Write(oImg,0,oImg.Length);
}
}