下载一个mdb文件并在客户端对其进行修改 [英] Download a mdb file and modify it in client side

查看:64
本文介绍了下载一个mdb文件并在客户端对其进行修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要下载一个mdb文件,并可以在客户端进行修改.我正在使用以下代码,但在阅读时不起作用:

 私有  Sub  btnDavid_Click( ByVal 发​​件人 As  对象 ByVal  e  As  System.EventArgs)句柄 btnDavid.Click


         Dim  sPathInforme  As  字符串 = 字符串.空

        sPathInforme =  CType (Server.MapPath(" 字符串)

         Dim  oFileStream  As  System.IO.FileStream

        oFileStream = System.IO.File.OpenWrite(sPathInforme + "  +  .mdb")

         Dim  mystream  As   New  MemoryStream

        mystream = StreamToMemory(oFileStream)

        oFileStream.Flush()
        oFileStream.Close()

        Response.Clear()

        Response.AppendHeader(" " 附件; filename = actas.mdb")

        Response.AppendHeader(" ,mystream.Length.ToString())

        '  Response.ContentType ="application/octet-stream" 
        Response.ContentType = " 

        Response.BinaryWrite(mystream.ToArray())

        响应.结束()
        mystream.Close()

    结束 

    ' 打开文件流进行读取,然后加载到内存流中
    公共 功能 StreamToMemory( ByVal  path  As  字符串) As  MemoryStream

         Dim 输入 As  FileStream
         Dim 输出 As  MemoryStream

        输入= 新建 FileStream(路径,FileMode.Open,FileAccess.Read,FileShare.Read)
        输出= StreamToMemory(输入)
        input.Close()

        返回输出

    结束 功能

    ' 将输入流的内容传输到内存流
    公共 功能 StreamToMemory( ByVal 输入 As 流) As  IO.MemoryStream

         Dim 缓冲区( 1023 ) As  字节
         Dim 计数 As  整数 =  1024 
         Dim 输出 As  MemoryStream

        ' 建立新的流
        如果输入.可以搜索然后
            输出= 新建 MemoryStream(input.Length)
        其他
            输出= 新建 MemoryStream
        结束 如果

        ' 迭代流并将其传输到内存流
        
            计数=输入.读取(缓冲区, 0 ,计数)
            如果 count =  0  >然后 退出 执行
            output.Write(buffer, 0 ,count)
        循环

        ' 倒带流
        output.Position =  0 

        ' 回传
        返回输出

    结束 功能 

解决方案

使用 WebClient.DownloadFile [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

解决方案

Use WebClient.DownloadFile[^] method ;)


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.


这篇关于下载一个mdb文件并在客户端对其进行修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆