[英]Save BinaryWrite to Server Path
I am saving files to SQL Server on remote hosted server. 我正在将文件保存到远程托管服务器上的SQL Server。 I can upload them.
我可以上传它们。 But I need to download a file to the remote servers path.
但是我需要将文件下载到远程服务器路径。 The code below extracts the file but saves it to the client.
下面的代码提取文件,但将其保存到客户端。
I tried replacing Response.BinaryWrite(bytes) to Response.TransmitFile( Server.MapPath("~/App_Data/DS/sailbig.jpg") but I get an error file not found. 我尝试将Response.BinaryWrite(bytes)替换为Response.TransmitFile(Server.MapPath(“〜/ App_Data / DS / sailbig.jpg”),但找不到错误文件。
I simply want to extract the file I stored in sql and place it a the directory on the server so I can use it in code later, but I cannot figure it out. 我只想提取存储在sql中的文件并将其放在服务器上的目录中,以便以后可以在代码中使用它,但我无法弄清楚。 Any help is appreciated, this is a hobby for me.
感谢您的帮助,这对我来说是一种爱好。
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()
Use File.WriteAllBytes : 使用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.