Click here to Skip to main content
15,922,015 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I need to download a mdb file and the possibility to modify it in cliente side. I´m using the following code but does not work when reading:

VB
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
Posted
Updated 4-Nov-11 4:39am
v2

Use WebClient.DownloadFile[^] method ;)
 
Share this answer
 
Comments
BUZONCORREOSVARIOS 25-Nov-11 1:58am    
The point is that I need the mdb file to be modified in server side, no hard disk recording. Something similar to Crystal Reports when creates a pdf file, pass a datatable and the client gets a customized report in pdf.
Maciej Los 25-Nov-11 10:12am    
Take a look here: http://www.codeproject.com/KB/aspnet/fileupload.aspx
"...uploading files via a web page was a tricky problem. The problem was that due to the encryption type of the form used to submit the file from the client's browser, receiving such files on the server side was a complex task. Data had to be retrieved as a safe byte array and decrypted before it could be used."
BUZONCORREOSVARIOS 29-Nov-11 2:07am    
Can I store a mdb file in a Oracle DataBase?, if so, how can I modify it with no hard disk recording before download it to the client side? (I mean insert, delete records to the mdb file). I have no permissions to save files in the server hard disk.

Thanks
The point is that I need the mdb file to be modified in server side, no hard disk recording. Something similar to Crystal Reports when creates a pdf file, pass a datatable and the client gets a customized pdf.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900