/
ivan
/
ModMas
Обзор
Документация
Войти
/
ivan
/
ModMas
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ModuleMaster/handlers/getfile.ashx
64 строки
2 KB
i.krivokon
Initial commit
13 мар 2026, 13:49
13 мар 2026, 13:49
00d9fb6
Код
Авторство
О чём код?
<%@ WebHandler Language="VB" Class="getFile" %> Imports System Imports System.Web Imports System.Data.SqlClient Imports System.IO Public Class getFile : Implements IHttpHandler Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Dim rowid = context.Request.QueryString("id") Dim storageName As String = context.Request.QueryString("storage") If IsNothing(storageName) Then storageName = "documents" End If Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("SERKIntranetConnectionString").ConnectionString) Dim com As New SqlCommand("SELECT [doc], [name] FROM " & storageName & " WHERE [id]=" & rowid, con) Dim f() As System.Byte = Nothing Dim fName As String = "" Dim fExtension As String = "" Try con.Open() Dim r As SqlDataReader = com.ExecuteReader While r.Read f = r.Item("doc") fName = r.Item("name") End While Catch ex As Exception Finally If con.State <> Data.ConnectionState.Closed Then con.Close() End If End Try With fName fExtension = .Substring(.IndexOf(".") + 1, .Length - .IndexOf(".") - 1).ToUpper End With Select Case fExtension Case "XLS", "XLSX" context.Response.ContentType = "application/vnd.ms-excel" Case "JPEG", "JPG" context.Response.ContentType = "image/jpeg" Case "DOC", "DOCX" context.Response.ContentType = "application/vnd.ms-word" Case "PDF" context.Response.ContentType = "application/pdf" Case Else context.Response.ContentType = "application/octet-stream" End Select context.Response.AppendHeader("Content-disposition", "attachment;filename=" & fName & ";") context.Response.AppendHeader("Content-Length", f.Length.ToString()) context.Response.Cache.SetCacheability(HttpCacheability.Public) context.Response.BufferOutput = False context.Response.OutputStream.Write(f, 0, f.Length) End Sub Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get Return False End Get End Property End Class