从网站跳出询问窗口是否下载文件(Content

摘要:从网站跳出询问窗口是否下载文件



 Response.ContentType = "application/x-zip-compressed"
            Response.AddHeader("Content-Disposition", "attachment; filename=""" & HttpUtility.UrlEncode("testZip.zip", System.Text.Encoding.Default) & """")
            Response.Clear()
            Response.WriteFile(strFileDirPath & "testZip.zip")
            Response.Flush()
            Response.Close()
            HttpContext.Current.ApplicationInstance.CompleteRequest()

当然这个test.zip文件事先已经先偷偷的保存在电脑里啰~~

一般在这段程序之前都会写一些写入文件的程序拉~然后会把test.zip藏在一个很难发现的地方

还有补充一下

1.Response.ContentType的种类多如牛毛,看你要给人家下载的文件是什么种类,再去google搜寻你要的种类吧

2.如果将Response封装在.vb类文件而非aspx.vb的时候,必须要在HttpContext.Current.Response底下response,如下


 With HttpContext.Current.Response
            .ContentType = "application/zip"
            .AddHeader("Content-Disposition", "attachment; filename=""" & HttpUtility.UrlEncode(strZipFileName, System.Text.Encoding.Default) & """")
            .Clear()
            .WriteFile(strFileDir & "" & strZipFileName)
            .Flush()
            .Close()
            
        End With
HttpContext.Current.ApplicationInstance.CompleteRequest()