Private Sub btnDavid_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDavid.Click Dim sPathInforme As String = String.Empty sPathInforme = CType(Server.MapPath("plantillas/"), String) Dim oFileStream As System.IO.FileStream oFileStream = System.IO.File.OpenWrite(sPathInforme + "actas" + ".mdb") Dim mystream As New MemoryStream mystream = StreamToMemory(oFileStream) oFileStream.Flush() oFileStream.Close() Response.Clear() Response.AppendHeader("Content-Disposition", "attachment; filename=actas.mdb") Response.AppendHeader("Content-Length", mystream.Length.ToString()) 'Response.ContentType = "application/octet-stream" Response.ContentType = "application/x-msaccess" Response.BinaryWrite(mystream.ToArray()) Response.End() mystream.Close() End Sub ' open a file stream for reading, and load into a memory stream Public Function StreamToMemory(ByVal path As String) As MemoryStream Dim input As FileStream Dim output As MemoryStream input = New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read) output = StreamToMemory(input) input.Close() Return output End Function ' transfer contents of input stream to memory stream Public Function StreamToMemory(ByVal input As Stream) As IO.MemoryStream Dim buffer(1023) As Byte Dim count As Integer = 1024 Dim output As MemoryStream ' build a new stream If input.CanSeek Then output = New MemoryStream(input.Length) Else output = New MemoryStream End If ' iterate stream and transfer to memory stream Do count = input.Read(buffer, 0, count) If count = 0 Then Exit Do output.Write(buffer, 0, count) Loop ' rewind stream output.Position = 0 ' pass back Return output End Function
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)