0

I'm a web developer that works with government agencies. Recently, I've gotten a request to make a fully searchable, indexed file repository for documents used by EMS and also the public. These are protocols for dealing with heart failure, overdoses, and other emergency situations No problems there.

The problem I have is figuring out a solution to provide up-to-date versions of those documents offline. While some of these protocols are well-established, others - for instance, Narcan - are constantly evolving and changing, and EMS staff are regularly in situations where Internet access may not be readily available, so I need a way to have those documents available locally offline, downloaded on a daily basis to their devices. I believe they use predominantly Android phones, but I'm sure there's Apple devices thrown in there as well.

Ideally, I'd like to use a script to accomplish this, but I'd be fine with something third-party that can schedule recurring downloads as well.

The documents are stored as blobs. The page I've got to display the documents currently embeds the response into a literal (I'm using ASP.NET) using a .ashx handler. Would this work if I provided the .ashx as a URL directly for the download?

 Public Sub ProcessRequest(context As HttpContext) Implements IHttpHandler.ProcessRequest
    Dim id As Integer = context.Request("Id")

    Dim bytes As Byte()
    Dim fileName As String
    Dim constr As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString

    context.Response.Buffer = True
    context.Response.Charset = ""

    Using con As New SqlConnection(constr)
        Using cmd As New SqlCommand()
            cmd.CommandText = "SELECT DocumentFile, Name FROM Documents WHERE DocumentID=@Id"
            cmd.Parameters.AddWithValue("@Id", id)
            cmd.Connection = con
            con.Open()
            Using sdr As SqlDataReader = cmd.ExecuteReader()
                sdr.Read()
                bytes = DirectCast(sdr("DocumentFile"), Byte())
                fileName = sdr("Name").ToString() + ".pdf"
            End Using
            con.Close()
        End Using
    End Using

    If context.Request.QueryString("download") = "1" Then
        context.Response.AppendHeader("Content-Disposition", Convert.ToString("attachment; filename=") & fileName)
    End If

    context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
    context.Response.ContentType = "application/pdf"

    context.Response.BinaryWrite(bytes)
    context.Response.Flush()
    context.Response.[End]()
End Sub
Ryan
  • 127
  • 1
  • 10

0 Answers0