PC Review


Reply
Thread Tools Rate Thread

Calling Response to WriteFile and also update page problem

 
 
John
Guest
Posts: n/a
 
      20th May 2010
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 Removed)




 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      21st May 2010
On May 20, 4:28*pm, "John" <johnwilh...@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...@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
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem opening Excel from Response.WriteFile output stream Jonathan Microsoft ASP .NET 0 20th Sep 2006 06:41 PM
placing response.writefile in web page Gert Albertse Microsoft ASP .NET 1 16th Aug 2005 04:49 PM
Response.writefile (filename) ?? problem with filesize =?Utf-8?B?ZG90bmV0dGVzdGVy?= Microsoft ASP .NET 2 16th Aug 2005 04:04 PM
Response.WriteFile set page title Grant Merwitz Microsoft ASP .NET 1 19th Apr 2005 08:03 PM
Problem to download excel file using Response.writefile Pankaj Garg Microsoft Dot NET 0 12th Jul 2004 05:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:23 PM.