Wednesday, 2 October 2013

Save BinaryWrite to Server Path

Save BinaryWrite to Server Path

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()

No comments:

Post a Comment