Public Function ResponseFile(ByRef PageResponse As HttpResponse, ByVal DownloadFileName As String, ByVal LocalFilePath As String, ByVal DownloadBuffer As Long) As Boolean
Dim Reader As System.IO.FileStream
Dim Buffer() As Byte
Dim FileLength As Long
Dim FileBuffer As Long = 1024 * DownloadBuffer
Dim ReadCount As Long
ReadCount = FileBuffer
ReDim Buffer(ReadCount - 1)
Try
Reader = System.IO.File.OpenRead(LocalFilePath)
FileLength = Reader.Length
Try
PageResponse.Buffer = False
PageResponse.AddHeader("Connection", "Keep-Alive")
PageResponse.ContentType = "application/octet-stream"
PageResponse.AddHeader("Content-Disposition", "attachment;filename=" + DownloadFileName)
PageResponse.AddHeader("Content-Length", FileLength.ToString)
While ReadCount = FileBuffer
ReadCount = Reader.Read(Buffer, 0, FileBuffer)
ReDim Preserve Buffer(ReadCount - 1)
PageResponse.BinaryWrite(Buffer)
End While
Response.End()
Catch ex As Exception
Return False
Finally
Reader.Close()
End Try
Catch ex As Exception
Return False
End Try
Return True
End Function
给你个我写的下载图片的代码,其它的,多研究研究flashget,自己动动脑
''' <summary>
''' 从互联网上加载图片
''' </summary>
''' <param name="URL">互联网上的图片路径</param>
''' <param name="SaveImagePath">用于存储下载下来的图片的路径,不包含文件名</param>
''' <remarks></remarks>
Public Sub AddImageFromURL(ByVal URL As String, ByVal SaveImagePath As String)
_DownURL = URL
_SourceImageFullPath = SaveImagePath '& "\" &
If _SourceImageFullPath.Substring(_SourceImageFullPath.Length - 1, 1) <> "\" Then
_SourceImageFullPath = SaveImagePath & "\"
End If
Try
If System.IO.Directory.Exists(_SourceImageFullPath) = False Then
System.IO.Directory.CreateDirectory(_SourceImageFullPath)
End If
Catch ex As Exception
End Try
_SourceImageFullPath = _SourceImageFullPath & System.IO.Path.GetFileName(URL)
Dim t As New Threading.Thread(AddressOf DownFileThread)
t.Start()
End Sub
''' <summary>
''' 下载文件的线程事件
''' </summary>
''' <remarks></remarks>
Private Sub DownFileThread()
Dim Myrq As HttpWebRequest = HttpWebRequest.Create(_DownURL)
Dim myrp As HttpWebResponse = Myrq.GetResponse
Dim totalBytes As Long = myrp.ContentLength
'Prog.Maximum = totalBytes
Dim st As Stream = myrp.GetResponseStream
Dim so As Stream = New FileStream(_SourceImageFullPath, FileMode.Create)
Dim totalDownloadedByte As Long = 0
Dim by(500) As Byte
Dim osize As Integer = st.Read(by, 0, by.Length)
While osize > 0
totalDownloadedByte = osize + totalDownloadedByte
Application.DoEvents()
so.Write(by, 0, osize)
'DrawProgress(CInt(totalDownloadedByte / myrp.ContentLength * 100))
'Prog.Value = totalDownloadedByte
osize = st.Read(by, 0, by.LongLength)
End While
so.Close()
st.Close()
While True
If File.Exists(_SourceImageFullPath) Then
_SourceImage = Image.FromFile(_SourceImageFullPath)
SetImageFormat()
Example_GetThumb()
DrawNoSelect()
Exit While
End If
End While
End Sub