繁体   English   中英

将BinaryWrite保存到服务器路径

[英]Save BinaryWrite to Server Path

我正在将文件保存到远程托管服务器上的SQL Server。 我可以上传它们。 但是我需要将文件下载到远程服务器路径。 下面的代码提取文件,但将其保存到客户端。

我尝试将Response.BinaryWrite(bytes)替换为Response.TransmitFile(Server.MapPath(“〜/ App_Data / DS / sailbig.jpg”),但找不到错误文件。

我只想提取存储在sql中的文件并将其放在服务器上的目录中,以便以后可以在代码中使用它,但我无法弄清楚。 感谢您的帮助,这对我来说是一种爱好。

    Dim filePath As String = HttpContext.Current.Server.MapPath("~/App_Data/DS/")
    Dim bytes() As Byte = CType(dt.Rows(0)("Data"), Byte())
    response.Buffer = True
    response.Charset = ""
    response.Cache.SetCacheability(HttpCacheability.NoCache)
    response.ContentType = dt.Rows(0)("ContentType").ToString()
    Response.AddHeader("content-disposition", "attachment;filename=" & dt.Rows(0)("FileName").ToString())
    Response.BinaryWrite(bytes)
    Response.Flush()
    Response.End()

使用File.WriteAllBytes

Dim filePath As String = HttpContext.Current.Server.MapPath("~/App_Data/DS/")
Dim bytes() As Byte = CType(dt.Rows(0)("Data"), Byte())

File.WriteAllBytes(filePath & dt.Rows(0)("FileName").ToString(), bytes)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM