[Original] Asp.net download the file in the form of a dialog box (VB.net)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.