473,386 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Download Page as Attachment

When a user clicks on a linkbutton on a page, i would like to render a printer-friendly version of the asp.net page and download it as an html attachment to the browser. The code below works great, with a few exceptions:

1) IE displays the FIle Download dialog box twice. (You have to click the Open button twice)
2) the encoding of the page is set to Western European (Windows) versus UTF-8.

#1 above is just a pain.
#2 above results in some wingding fonts to be displayed incorrectly in the page.

Anyone have suggestions on how to fix these problems or see any problems in the code? #2 is our highest priority.

CODE:

// this code is implemented in the Render method of the page
// when a user click the button, it sets renderAsAttachement = true, and adds the desired controls to be rendered
// to the propControlContainer Controls collection
protected override void Render(HtmlTextWriter writer)

{

if (renderAsAttachement)
{
Response.Clear();
Response.ContentEncoding = Encoding.UTF8;
Response.Charset = "utf-8";

Response.AppendHeader("Content-Disposition", String.Format("attachment;Filename=\"{0}\"", "Document1.htm"));
Response.ContentType = "text/html";

writer.WriteFullBeginTag("html");
writer.WriteLine();
writer.WriteFullBeginTag("head");
writer.WriteLine();
writer.Write(Globals.ColorScheme); // this renders a style sheet that is used by the page
writer.WriteLine();
writer.WriteEndTag("head");
writer.WriteLine();
writer.WriteFullBeginTag("body style=\"padding:5pt;\"");
writer.WriteLine();

propControlContainer.RenderControl(writer); // this is a parent control that renders all the child controls (in it's control collection)
// that are to be included in the "printer-friendly" version of the page

writer.WriteEndTag("body");
writer.WriteLine();
writer.WriteEndTag("html");
writer.WriteLine();

Response.End();
}
else
{
base.Render(writer);
}
}
Nov 18 '05 #1
7 2236
Hi Brian,

Thank you for posting in Microsoft Newsgroup. Regarding on the issue, I am
finding proper resource to assist you and we will update as soon as
posible.

Regards,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #2
thanks Luke!
"MSFT" <lu******@online.microsoft.com> wrote in message
news:1J***************@cpmsftngxa07.phx.gbl...
Hi Brian,

Thank you for posting in Microsoft Newsgroup. Regarding on the issue, I am finding proper resource to assist you and we will update as soon as
posible.

Regards,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #3
Hi Brian Paul,
Thank you for using Microsoft Newsgroup service. Based on your description,
you had a aspx page to provide a certain format html document for the user
to open in browsr or download to client. The html document has some
"printer-friendly" data( are they all unicode data?). Also, you set the
page's Header as
Response.AppendHeader("Content-Disposition",
String.Format("attachment;Filename=\"{0}\"", "Document1.htm")); to force
the download dialog to popup and set the charset as "UTF-8"

However, when you run the page and fire the download operation, you
encountered two problems:
1. the download dialog popup twice
2. some of the html document's data doesn't display correctly

Please correct me if my understanding or your problem is not quite accurate.

As for the above two problems I've done some tested on them. I also met the
first problem, it is a bit strange why the dialog popup twice. I'll do some
further research on it and I also find a way to workaround the problem:
Just using another page to render the document output which will be
downloaded or opened. Add the "render" method in this page.

In the original page, just use a simple hyperlink which point to document
page, such as
<a href="showdoc.aspx">open document</a>

the "showdoc.aspx" is just the page which has the "render? method to
generate the "printer-friendly data and show download dialog.
Thus, the pop dialog won't popup twice.
As for the second problem. You said that " the encoding of the page is set
to Western European (Windows) versus UTF-8" and some "wingding fonts "
doesn't display correctly. Do you means that when the document is opended
in the browser, the Encoding of the browser is set as "western European"
rather than "UTF-8"? And if you change the browser's view->encoding to
"UTF-8", does those "wingding fonts " display correctly?
If it can display correctly when you set the browser's view->encoding as
"UTF-8", the problem is caused by the client browser's default encoding
setting. Since the default encoding of the client browser is set as
"western European", when you open a certain page in the browser, it will
always first display using the default setting. This feature is not set via
the serverside code.

If the "wingding fonts" still can't display correctly when you chang the
browsesr's view->encoding to "UTF-8", I think the problem is likely due to
the "wingding fonts" which can't display well in UTF-8. Thus, would you
please provide some of the "wingding fonts" which can't display well so
that I can do further research on them?
Please try out the preceding suggestion to see whether it helps. Also if
you have any questions on it, please feel free to let me know.
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4
Hi Steven,

Thanks very much for your time on this. I sure appreciate it your support.
You found the problem to #2. See my responses in CAPS inline below:

thanks again!!!

"MSFT" <v-******@online.microsoft.com> wrote in message
news:3Y**************@cpmsftngxa07.phx.gbl...
Hi Brian Paul,
Thank you for using Microsoft Newsgroup service. Based on your description, you had a aspx page to provide a certain format html document for the user
to open in browsr or download to client. The html document has some
"printer-friendly" data( are they all unicode data?). Also, you set the
page's Header as
Response.AppendHeader("Content-Disposition",
String.Format("attachment;Filename=\"{0}\"", "Document1.htm")); to force
the download dialog to popup and set the charset as "UTF-8"

However, when you run the page and fire the download operation, you
encountered two problems:
1. the download dialog popup twice
2. some of the html document's data doesn't display correctly

Please correct me if my understanding or your problem is not quite accurate.
As for the above two problems I've done some tested on them. I also met the first problem, it is a bit strange why the dialog popup twice. I'll do some further research on it and I also find a way to workaround the problem:
Just using another page to render the document output which will be
downloaded or opened. Add the "render" method in this page.

In the original page, just use a simple hyperlink which point to document
page, such as
<a href="showdoc.aspx">open document</a>

the "showdoc.aspx" is just the page which has the "render? method to
generate the "printer-friendly data and show download dialog.
Thus, the pop dialog won't popup twice.
THANKS FOR THE SUGGESTION, HOWEVER, IT'S A LOT MORE WORK THAN MY CURRENT
IMPLEMENTATION.

HERE'S WHY:

IN MOST CASES DATAGRIDS ARE THE CONTROLS TO BE RENDERED ON EACH PAGE. THE
PAGE ALLOWS FILTERS TO BE SET FOR THE DATAGRID. YOU CAN ALSO SORT THE DATA
BY CLICKING ON THE HEADER COLUMN WITHIN EACH DATAGRID.

USING A SEPERATE PAGE REQUIRES ME TO PASS ALL THE FILTER AND SORT PARAMS TO
THE 2ND PAGE AND RE-DATABIND ALL THE GRID(S) (REQUIRING ANOTHER ROUND TRIP
TO THE DB).

USING THE SAME PAGE IS MUST SIMPLER AND EFFICIENT. I DON'T HAVE TO SEND ALL
THE PAGE PARAMS, AND I DON'T EVEN HAVE TO RE-DATABIND THE GRIDS. I JUST ADD
THE GRID TO THE RENDER FUNCTION OF THE PARENT PAGE AND THE GRID(S) ARE
RENDERED BASED ON THEIR CURRENT VIEWSTATE.

IF AT ALL POSSIBLE, I WOULD LIKE TO STAY WITH THE SINGLE PAGE
IMPLEMENTATION.

-----
AFTER MORE INITIAL TESTING I HAVE FOUND THAT SOME VERSIONS OF IE6 ON WINXP
DON'T PROMPT TWO DIALOGS. THE IE VERSIONS ARE THE SAME, BUT ONE HAS MORE
UPDATES:

THIS ONE PROMPTS TWICE:
IE VERSION ON WINXP: 6.0.2800.1106.XPSP2.030422-1633
UPDATES: SP1, Q328970, Q324929, Q810847, Q813951, Q813489, Q330994, Q818529,
Q822925, Q828750, 824145

THIS ONE PROMPTS ONCE:
IE VERSION ON WINXP: 6.0.2800.1106.XPSP2.030422-1633
UPDATES: SP1, Q810847, Q813951, Q813489, Q330994, Q818529, Q822925, Q828750,
824145
IT DOES NOT INCLUDE: Q328970, Q324929 ....SO MAYBE IT HAS SOMETHING TO DO
WITH ONE OF THESE UDPATES.
As for the second problem. You said that " the encoding of the page is set
to Western European (Windows) versus UTF-8" and some "wingding fonts "
doesn't display correctly. Do you means that when the document is opended
in the browser, the Encoding of the browser is set as "western European"
rather than "UTF-8"?
YES, THAT IS CORRECT.

And if you change the browser's view->encoding to "UTF-8", does those "wingding fonts " display correctly?
YES, THAT FIXED IT!!!! ONE QUESTION THOUGH, OUT OF THE BOX, WHAT IS IE'S
DEFAULT ENCODING? I DON'T RECALL CHANGING THIS SETTING ON ANY OF OUR TEST
MACHINES.
If it can display correctly when you set the browser's view->encoding as
"UTF-8", the problem is caused by the client browser's default encoding
setting. Since the default encoding of the client browser is set as
"western European", when you open a certain page in the browser, it will
always first display using the default setting. This feature is not set via the serverside code.

If the "wingding fonts" still can't display correctly when you chang the
browsesr's view->encoding to "UTF-8", I think the problem is likely due to
the "wingding fonts" which can't display well in UTF-8. Thus, would you
please provide some of the "wingding fonts" which can't display well so
that I can do further research on them?
Please try out the preceding suggestion to see whether it helps. Also if
you have any questions on it, please feel free to let me know.
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #5
Hi Steven,

After doing more testing with issue #2 below i've found that when the
document opens as an attachment in the new window, the encoding always
defaults to Western European (Windows) -- even after the default setting in
IE under View/Encoding is set to UTF-8. In the new window once the document
has opened, if i change the encoding to UTF-8, the Wingding font (a checkbox
symbol) is displayed correctly. However, this is a pain to require the
user's to do this each time. Is there a way to ensure the new window opens
using UTF-8?

thanks,
Brian

"Brian Paul" <br****@ekyros.com> wrote in message
news:Of**************@TK2MSFTNGP12.phx.gbl...
Hi Steven,

Thanks very much for your time on this. I sure appreciate it your support. You found the problem to #2. See my responses in CAPS inline below:

thanks again!!!

"MSFT" <v-******@online.microsoft.com> wrote in message
news:3Y**************@cpmsftngxa07.phx.gbl...
Hi Brian Paul,
Thank you for using Microsoft Newsgroup service. Based on your description,
you had a aspx page to provide a certain format html document for the user to open in browsr or download to client. The html document has some
"printer-friendly" data( are they all unicode data?). Also, you set the
page's Header as
Response.AppendHeader("Content-Disposition",
String.Format("attachment;Filename=\"{0}\"", "Document1.htm")); to force
the download dialog to popup and set the charset as "UTF-8"

However, when you run the page and fire the download operation, you
encountered two problems:
1. the download dialog popup twice
2. some of the html document's data doesn't display correctly

Please correct me if my understanding or your problem is not quite

accurate.

As for the above two problems I've done some tested on them. I also met

the
first problem, it is a bit strange why the dialog popup twice. I'll do

some
further research on it and I also find a way to workaround the problem:
Just using another page to render the document output which will be
downloaded or opened. Add the "render" method in this page.

In the original page, just use a simple hyperlink which point to document page, such as
<a href="showdoc.aspx">open document</a>

the "showdoc.aspx" is just the page which has the "render? method to
generate the "printer-friendly data and show download dialog.
Thus, the pop dialog won't popup twice.

THANKS FOR THE SUGGESTION, HOWEVER, IT'S A LOT MORE WORK THAN MY CURRENT
IMPLEMENTATION.

HERE'S WHY:

IN MOST CASES DATAGRIDS ARE THE CONTROLS TO BE RENDERED ON EACH PAGE. THE
PAGE ALLOWS FILTERS TO BE SET FOR THE DATAGRID. YOU CAN ALSO SORT THE

DATA BY CLICKING ON THE HEADER COLUMN WITHIN EACH DATAGRID.

USING A SEPERATE PAGE REQUIRES ME TO PASS ALL THE FILTER AND SORT PARAMS TO THE 2ND PAGE AND RE-DATABIND ALL THE GRID(S) (REQUIRING ANOTHER ROUND TRIP
TO THE DB).

USING THE SAME PAGE IS MUST SIMPLER AND EFFICIENT. I DON'T HAVE TO SEND ALL THE PAGE PARAMS, AND I DON'T EVEN HAVE TO RE-DATABIND THE GRIDS. I JUST ADD THE GRID TO THE RENDER FUNCTION OF THE PARENT PAGE AND THE GRID(S) ARE
RENDERED BASED ON THEIR CURRENT VIEWSTATE.

IF AT ALL POSSIBLE, I WOULD LIKE TO STAY WITH THE SINGLE PAGE
IMPLEMENTATION.

-----
AFTER MORE INITIAL TESTING I HAVE FOUND THAT SOME VERSIONS OF IE6 ON WINXP
DON'T PROMPT TWO DIALOGS. THE IE VERSIONS ARE THE SAME, BUT ONE HAS MORE
UPDATES:

THIS ONE PROMPTS TWICE:
IE VERSION ON WINXP: 6.0.2800.1106.XPSP2.030422-1633
UPDATES: SP1, Q328970, Q324929, Q810847, Q813951, Q813489, Q330994, Q818529, Q822925, Q828750, 824145

THIS ONE PROMPTS ONCE:
IE VERSION ON WINXP: 6.0.2800.1106.XPSP2.030422-1633
UPDATES: SP1, Q810847, Q813951, Q813489, Q330994, Q818529, Q822925, Q828750, 824145
IT DOES NOT INCLUDE: Q328970, Q324929 ....SO MAYBE IT HAS SOMETHING TO DO
WITH ONE OF THESE UDPATES.

As for the second problem. You said that " the encoding of the page is set to Western European (Windows) versus UTF-8" and some "wingding fonts "
doesn't display correctly. Do you means that when the document is opended in the browser, the Encoding of the browser is set as "western European"
rather than "UTF-8"?


YES, THAT IS CORRECT.

And if you change the browser's view->encoding to
"UTF-8", does those "wingding fonts " display correctly?


YES, THAT FIXED IT!!!! ONE QUESTION THOUGH, OUT OF THE BOX, WHAT IS IE'S
DEFAULT ENCODING? I DON'T RECALL CHANGING THIS SETTING ON ANY OF OUR TEST
MACHINES.
If it can display correctly when you set the browser's view->encoding as
"UTF-8", the problem is caused by the client browser's default encoding
setting. Since the default encoding of the client browser is set as
"western European", when you open a certain page in the browser, it will
always first display using the default setting. This feature is not set

via
the serverside code.

If the "wingding fonts" still can't display correctly when you chang the
browsesr's view->encoding to "UTF-8", I think the problem is likely due to the "wingding fonts" which can't display well in UTF-8. Thus, would you
please provide some of the "wingding fonts" which can't display well so
that I can do further research on them?
Please try out the preceding suggestion to see whether it helps. Also if
you have any questions on it, please feel free to let me know.
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Nov 18 '05 #6


Hi Brian ,
Thank you for the prompt response. As the problem you descirbed in the
response, I think you can try this:

In IE, click View, point to Encoding. Uncheck "Auto Select" and select
"UTF-8"

Please do uncheck the "Auto Select", then, when you open IE in other
document, the Encoding will focus on "UTF-8"

However, since such operations are on client side. So if the user used to
set the IE's encoding as other options(not UTF-8). He still should to
change it manually. Also, I've reviewed some references on IE'S setting,
the algorism IE uses to set encoding for a page is below:

1. If the web page has set the language encoding to use, IE will use the
encodin
g.

2. If the web page has not set the language encoding to use and IE uses
Auto-Sel
ect, IE will determine which one is the best encoding.

3. If the web page has not set the language encoding to use and IE doesn¡¯t
uses
Auto-Select, IE will use the default encoding. The fault encoding is at
[HKEY_C
URRENT_USER\Software\Microsoft\Internet Explorer\International]
Defalt_CodePage.
Yes, generally, wo may try editing the registry via script(such as change
IE'S print setting). However, for the encoding setting, IE has its own
algorism to decide the encoding method, customer cannot use her own ActiveX
control(also script) to change it.

If you have any questions on it, please feel free to let me know.
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #7
Here's what i've come up with which fixes both issues:

1) Render the controls to a new HtmlTextWriter
2) convert the rendered control text to a byte array
3) store it to a image type in a db.
4) then Response.Redirect() to a printerfriendly.aspx and pass the record id
of the rendered content from step 3.

by persisting the content to the db and redirecting to a second page:

1) IE does not prompt the open dialog twice.
2) the encoding seems to work correctly.

I haven't had a chance to test for performance. but we are using a pretty
hefty (dual proc/gobs of ram) db server. So i'm hoping performance will be
ok.
"MSFT" <v-******@online.microsoft.com> wrote in message
news:qG**************@cpmsftngxa07.phx.gbl...


Hi Brian ,
Thank you for the prompt response. As the problem you descirbed in the
response, I think you can try this:

In IE, click View, point to Encoding. Uncheck "Auto Select" and select
"UTF-8"

Please do uncheck the "Auto Select", then, when you open IE in other
document, the Encoding will focus on "UTF-8"

However, since such operations are on client side. So if the user used to
set the IE's encoding as other options(not UTF-8). He still should to
change it manually. Also, I've reviewed some references on IE'S setting,
the algorism IE uses to set encoding for a page is below:

1. If the web page has set the language encoding to use, IE will use the
encodin
g.

2. If the web page has not set the language encoding to use and IE uses
Auto-Sel
ect, IE will determine which one is the best encoding.

3. If the web page has not set the language encoding to use and IE doesn¡¯t uses
Auto-Select, IE will use the default encoding. The fault encoding is at
[HKEY_C
URRENT_USER\Software\Microsoft\Internet Explorer\International]
Defalt_CodePage.
Yes, generally, wo may try editing the registry via script(such as change
IE'S print setting). However, for the encoding setting, IE has its own
algorism to decide the encoding method, customer cannot use her own ActiveX control(also script) to change it.

If you have any questions on it, please feel free to let me know.
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: peetm | last post by:
I'd like to write to a log whenever a visitor to my site downloads a file. So, I'd like the link they click to be to a php 'page' that returns the file. Don't know how to do that! Side...
13
by: Ken | last post by:
How do I download files from the internet server to my computer? How do I tell the script the correct hard drive folder on my computer to copy the files to? After connecting to the internet...
2
by: Tom Youngquist | last post by:
I am trying to download a text file that my .NET page has just created based on entered parameters on the web page. Everything seems to work and the file is created. I am using the following code...
2
by: Sleepy | last post by:
I am wanting to allow a client to download a file from a web server and save it on their local PC. The only way that I have found to do this is to use HTTP headers. I am using the code shown below...
2
by: moondaddy | last post by:
I have a asp.net app where a user will need to download multiple files at once. Below is some sample code I'm using to download a single file which works perfectly, however, rather than a single...
1
by: GRE | last post by:
I'm hoping someone can help with this problem; I've seen only a handful of postings related to it, but with no clear resolution. I have an ASP.NET 1.1 page that downloads requested files via the...
1
by: ckarbass | last post by:
I'd like for the file download dialog to be launched upon page load. The workflow or behavior is exactly the same as sourceforge's. I've searched on google to no avail. Any help would be...
2
by: allan.s.palmer | last post by:
Hello, I have an asp.net pop up that is generating a Word document real time and sending it to the user by sending the appropriate response headers. When it is run on our development environment...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.