From: John on
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

johnwilhelm(a)charter.net




From: Alexey Smirnov on
On May 20, 4:28 pm, "John" <johnwilh...(a)charter.net> wrote:
> 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
>
> johnwilh...(a)charter.net

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