Private Sub Page_Load (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles MyBase. Load
'User code to place the initialization page here
Dim imgUrl As String = Me. Request. QueryString ("url") '// obtain the physical path of the file.
Me. DownloadFile (imgUrl)
End Sub
Private Function DownloadFile (ByVal filename As String)
Dim saveFileName As String
Dim startIndex As Int32 = filename. LastIndexOf ("\") + 1
SaveFileName = filename. Substring (startIndex)
Dim fi As System. IO. FileInfo = New System. IO. FileInfo (filename)
Dim fileExtName As String = fi. Extension
Dim DEFAULT_CONTENT_TYPE As String = "application/unknown"
Dim regKey, fileExtKey As Microsoft. Win32.RegistryKey
Dim fileContentType As String
Try
RegKey = Microsoft. Win32.Registry. ClassesRoot
FileExtKey = regKey. OpenSubKey (fileExtName)
FileContentType = fileExtKey. GetValue ("Content Type", DEFAULT_CONTENT_TYPE)
Catch ex As Exception
FileContentType = DEFAULT_CONTENT_TYPE
End Try
Me. Response. Clear ()
Response. Charset = "UTF-8"
Me. Response. Buffer = True
Me. EnableViewState = False
Me. Response. ContentEncoding = System. Text. Encoding. UTF8
Me. Response. AppendHeader ("Content-Disposition", "attachment; filename =" & saveFileName)
Me. Response. ContentType = fileContentType
Me. Response. WriteFile (filename)
Me. Response. Flush ()
Me. Response. End ()
End Function
My program can download JPG images and other files, but the file name in the SAVE dialog box cannot be normally displayed (garbled characters are displayed) if it is a Chinese character, and the letters and numbers are displayed normally, I hope you can help solve this problem. Thank you first