I want to allow users to download files that have names containing & characters.
We've escaped our way through the problem but cannot seem to get around one last obstacle.
Here in Download.asp.vb we have
And here is where it fails - the attachment; filename= line.Code:Imports System.IO Partial Class Clients_Download Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim ctx As HttpContext = HttpContext.Current Dim response As HttpResponse = ctx.Response Dim sFile As String = Request.QueryString("filename".ToString) ' Buffer to read 10K bytes in chunk: Dim buffer(10000) As Byte ' Length of the file: Dim length As Integer ' Total bytes to read: Dim dataToRead As Long ' Identify the file to download including its path. Dim filepath As String = sFile ' Identify the file name. Dim filename As String = System.IO.Path.GetFileName(filepath) Using iStream As New FileStream(filepath, System.IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read) ' Total bytes to read: dataToRead = iStream.Length response.ContentType = "application/octet-stream" response.AddHeader("Content-Disposition", "attachment; filename=" & filename)
The filename vbl has the & character within it.
The pop-up that appears in the browser window asking for where to save the file shows a filename WITHOUT the &'s.
Here is the continuation of the codeCode:' Read the bytes. While dataToRead > 0 ' Verify that the client is connected. If response.IsClientConnected Then ' Read the data in buffer length = iStream.Read(buffer, 0, 10000) ' Write the data to the current output stream. response.OutputStream.Write(buffer, 0, length) ' Flush the data to the HTML output. response.Flush() ReDim buffer(10000) ' Clear the buffer dataToRead = dataToRead - length Else 'prevent infinite loop if user disconnects dataToRead = -1 End If End While iStream.Close() 'delete the file after downloading it If Request.QueryString("delfile") = "true" Then 'make sure it contains \temp\ dir If sFile.Contains("\temp\") Then File.Delete(sFile) End If End If response.End() End Using End Sub




Reply With Quote