M
moondaddy
Using vb.net I need to download image files to the client browser where they
can save to disk. Below is some sample code I'm using. when I run this the
File Download window in the browser says:
File name: ViewAttachment
File type:
From localhost
1) "ViewAttachment" is the name of the aspx page and not the image file.
2) Its not picking up the file type of jpg. For ContentType I used
image/pjpeg becuase thats what i say when I ran some sample code to upload
the picture but I dont know for sure if thats correct for this code snippet.
3) when I open the file its all mumbo jumbo numbers.
Where am I going wrong?
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim path As String = Server.MapPath(".") & "\images\test\Winter.jpg"
Dim fs As New FileStream(path, FileMode.Open)
Dim byteRead As Integer
Response.ClearHeaders()
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment;filename=" & path)
Response.ContentType = "image/pjpeg"
'Response.WriteFile(path) 'NOTE: If I use this line I get an error
saying that the file is already in use.
byteRead = fs.ReadByte()
While byteRead <> -1
Response.Write(byteRead)
byteRead = fs.ReadByte()
End While
fs.Close()
End Sub
can save to disk. Below is some sample code I'm using. when I run this the
File Download window in the browser says:
File name: ViewAttachment
File type:
From localhost
1) "ViewAttachment" is the name of the aspx page and not the image file.
2) Its not picking up the file type of jpg. For ContentType I used
image/pjpeg becuase thats what i say when I ran some sample code to upload
the picture but I dont know for sure if thats correct for this code snippet.
3) when I open the file its all mumbo jumbo numbers.
Where am I going wrong?
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim path As String = Server.MapPath(".") & "\images\test\Winter.jpg"
Dim fs As New FileStream(path, FileMode.Open)
Dim byteRead As Integer
Response.ClearHeaders()
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment;filename=" & path)
Response.ContentType = "image/pjpeg"
'Response.WriteFile(path) 'NOTE: If I use this line I get an error
saying that the file is already in use.
byteRead = fs.ReadByte()
While byteRead <> -1
Response.Write(byteRead)
byteRead = fs.ReadByte()
End While
fs.Close()
End Sub