I am saving files to SQL Server on remote hosted 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.
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. 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 :
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.