We have the following ASP.NET code to download a CSV file from Response.Output.Write.
The iOS PWA (web app) downloads the file but provides no way back to the PWA app.
How can we avoid that 'no way back' page?
Here is the code we have to download the CSV file:
Private Function fCSVOutputCreateFile() As Boolean
'Create the File Name
Dim strFileName As String = ""
Dim strFileNameZip As String = ""
Dim strYearProxy As String = ""
Select Case DropDownListDataName.SelectedValue
Case "Accounts"
Case "Admins"
Case Else
strYearProxy = "-" + DropDownListYear.SelectedValue.ToString
End Select
Dim bld1 As New StringBuilder
With bld1
.Append(strClsAppName)
.Append("-")
.Append(strClsUserType)
.Append("-")
.Append(lngClsUserTypeID.ToString)
.Append("-")
.Append(DropDownListDataName.SelectedItem.Text.Replace(" ", "-"))
.Append(strYearProxy)
.Append(".csv")
strFileName = .ToString
End With
'Set compression option if given or auto-set
If fAutoCompressRequired() = True Then
Return False
End If
If CheckBoxCompressData.Checked = True Then
'Create zip filename
strFileNameZip = Left(strFileName, strFileName.Length - 4) + ".zip"
'Compress and download
Dim bytFile1 As Byte() = System.Text.Encoding.Unicode.GetBytes(strClsCSVOutputData)
Using ms As MemoryStream = New MemoryStream()
Using archive = New ZipArchive(ms, ZipArchiveMode.Create, True)
Dim zipArchiveEntry = archive.CreateEntry(strFileName, CompressionLevel.Fastest)
Using zipStream = zipArchiveEntry.Open()
zipStream.Write(bytFile1, 0, bytFile1.Length)
End Using
End Using
'Response
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/octet-stream"
Response.Headers.Add("Content-Disposition", "attachment; filename=" + strFileNameZip)
ms.Seek(0, SeekOrigin.Begin)
ms.WriteTo(Response.OutputStream)
Response.Flush()
Response.Close()
Response.End()
End Using
Else
'Download the CSV file
Response.Clear()
Response.Buffer = True
Response.AddHeader("content-disposition", "attachment;filename=" + strFileName)
Response.Charset = ""
Response.ContentType = "application/text"
Response.Output.Write(strClsCSVOutputData)
Response.Flush()
Response.End()
End If
End Function
Any suggestions appreciated.
UPDATE 1:
I tried the suggestion shown in the comments by Andrew Morton but the IOS PWA still went to the same screen with no back ability, even though on the desktop it stayed on the same page.
~\pages\test\download\hdl1.ashx:
<%@ WebHandler Language="VB" Class="hdl1" %>
Imports System
Imports System.Web
Public Class hdl1 : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
HttpContext.Current.Response.ClearContent()
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=1234.csv")
HttpContext.Current.Response.ContentType = "application/text"
HttpContext.Current.Response.Write("1a,2,3,4")
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
~\pages\test\download\default.aspx:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="default.aspx.vb" Inherits="pages_test_ashx_default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:LinkButton ID="LinkButton1" runat="server">Download</asp:LinkButton>
</div>
</form>
</body>
</html>
~\pages\test\download\default.aspx.vb
Partial Class pages_test_ashx_default
Inherits System.Web.UI.Page
Private Sub LinkButton1_Click(sender As Object, e As EventArgs) Handles LinkButton1.Click
Response.Redirect("~/pages/test/download/hdl1.ashx")
End Sub
End Class