Calling Response to WriteFile and also update page problem

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hello,

I have a VB.net app the sends an Excel file to the browser and it also need
to hide some fields on the form at the same time. But the form is not hiding
the controlls. The "Open/Save/Cancel" diaolog opens on the browser but the
page stays the same, the controls are not hidden. Below is a sample of the
code I'm using to send the file to the browser and hide the controls. What
am I doing wrong?

Sub SendReport(ByRef SaveFile As String)

tblMessage.Visible = False

lblMessage.Text = ""

'Response.Flush()

'Response.Close()

'Response.ClearContent()

'Response.ClearHeaders()

Response.ContentType = "application/vnd.ms-excel"

Response.WriteFile(SaveFile)

Response.End()

'Response.Flush()

'Response.Close()

Kill(SaveFile)

End Sub



Thanks,

John Wilhelm

(e-mail address removed)
 
Hello,

I have a VB.net app the sends an Excel file to the browser and it also need
to hide some fields on the form at the same time. But the form is not hiding
the controlls. The "Open/Save/Cancel" diaolog opens on the browser but the
page stays the same, the controls are not hidden. Below is a sample of the
code I'm using to send the file to the browser and hide the controls. What
am I doing wrong?

Sub SendReport(ByRef SaveFile As String)

    tblMessage.Visible = False

    lblMessage.Text = ""

    'Response.Flush()

    'Response.Close()

    'Response.ClearContent()

    'Response.ClearHeaders()

    Response.ContentType = "application/vnd.ms-excel"

    Response.WriteFile(SaveFile)

    Response.End()

    'Response.Flush()

    'Response.Close()

    Kill(SaveFile)

End Sub

Thanks,

John Wilhelm

(e-mail address removed)

Hi John,

after you set ContentType = "application/vnd.ms-excel" and call
Response.End you will not be able to "refresh" the page. That's
because you cannot combine text/html and application/vnd.ms-excel in
the same response. You can try to fix it by doing a small trick with
meta tag

instead of

Response.ContentType = "application/vnd.ms-excel"
Response.WriteFile(SaveFile)
Response.End()
Kill(SaveFile)

do

Dim meta As HtmlMeta = New HtmlMeta()
meta.HttpEquiv = "Refresh"
meta.Name = "keywords"
meta.Content = "0;URL=" & SaveFile <-- e.g. mydoc.xls
Me.Header.Controls.Add(meta)

Hope this helps
 
Back
Top