473,217 Members | 2,099 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,217 software developers and data experts.

Save ASPX page on client programmatically

Hello,

the scenario:

There's an ASPX page which shows some text and has three buttons at the
bottom: Save, Print and Close. Print and close is done by javascript. But how
can I save the page on the client's computer? He/she could do this using the
browser (file/save), but I need to have it done by pressing the pushbutton.

In my serverside code I get the button-click-event, I also know how to get
data to the client (including file-save-dialog), but where can I get the
page's content?

The download code could look like this (with ??? being actually my question):

Response.AddHeader("Content-Disposition", "attachment;
filename=Contract.html");
Response.AddHeader("Content-Length", ???.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Write(???);
Response.End();

Maybe I'm completely wrong and there is an other better way to do it. Please
help!
Mar 2 '07 #1
12 4726
It depends on what do you want user to save. Since it is web application,
all user gets is a page rendered in a browser, according to HTML tags. If
you want user to save the page as it is, then the browser's "Save" menu is
what it means, why try to invent the wheel again. If what you want user to
save is the data displayed on the page, but in different format (say, PDF),
you need then to re-organise your data in wanted format and send to browser
as download stream. Or because of the current page has too many decorations,
you want to save a clean printable version, then you can simply make a plain
printable version of the page, to let user still be able to save with
standard browser "Save" command.

I do not see the point when user can save the page easily, while you still
want him to save the exactly same page as download via a "Save" button.
"FreeNEasy" <Fr*******@community.nospamwrote in message
news:B1**********************************@microsof t.com...
Hello,

the scenario:

There's an ASPX page which shows some text and has three buttons at the
bottom: Save, Print and Close. Print and close is done by javascript. But
how
can I save the page on the client's computer? He/she could do this using
the
browser (file/save), but I need to have it done by pressing the
pushbutton.

In my serverside code I get the button-click-event, I also know how to get
data to the client (including file-save-dialog), but where can I get the
page's content?

The download code could look like this (with ??? being actually my
question):

Response.AddHeader("Content-Disposition", "attachment;
filename=Contract.html");
Response.AddHeader("Content-Length", ???.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Write(???);
Response.End();

Maybe I'm completely wrong and there is an other better way to do it.
Please
help!

Mar 2 '07 #2
Wrong newsgroup, but you can probably usee something like document.innerHTML
or document.innerText or something.

The problem with that is that it won't include images or anything included
etc. IE's client save is actually doing a lot of work.

"FreeNEasy" <Fr*******@community.nospamwrote in message
news:B1**********************************@microsof t.com...
Hello,

the scenario:

There's an ASPX page which shows some text and has three buttons at the
bottom: Save, Print and Close. Print and close is done by javascript. But
how
can I save the page on the client's computer? He/she could do this using
the
browser (file/save), but I need to have it done by pressing the
pushbutton.

In my serverside code I get the button-click-event, I also know how to get
data to the client (including file-save-dialog), but where can I get the
page's content?

The download code could look like this (with ??? being actually my
question):

Response.AddHeader("Content-Disposition", "attachment;
filename=Contract.html");
Response.AddHeader("Content-Length", ???.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Write(???);
Response.End();

Maybe I'm completely wrong and there is an other better way to do it.
Please
help!

Mar 2 '07 #3
@Norman:

You are right, the browser's save function would be fine for this. There are
two reasons why I need to have a button on the page for it:

reason 1: Without the intention to offend someone: there ARE users out there
who don't know THAT and HOW they can save a page displayed in their browser.
Since the document is a contract document and it is important that the user
can save it, (and does save it) a clearly visible save-button is the more
secure way to have the document saved.

reason 2: I am programming this for a customer and he WANTS the save-button.

Besides, if I would like to modify the content for formatting etc. I first
need to have the content. The ASPX page ist made of a form with text and
fields, how can I get the rendered content, I can't find it.

"Norman Yuan" wrote:
It depends on what do you want user to save. Since it is web application,
all user gets is a page rendered in a browser, according to HTML tags. If
you want user to save the page as it is, then the browser's "Save" menu is
what it means, why try to invent the wheel again. If what you want user to
save is the data displayed on the page, but in different format (say, PDF),
you need then to re-organise your data in wanted format and send to browser
as download stream. Or because of the current page has too many decorations,
you want to save a clean printable version, then you can simply make a plain
printable version of the page, to let user still be able to save with
standard browser "Save" command.

I do not see the point when user can save the page easily, while you still
want him to save the exactly same page as download via a "Save" button.
"FreeNEasy" <Fr*******@community.nospamwrote in message
news:B1**********************************@microsof t.com...
Hello,

the scenario:

There's an ASPX page which shows some text and has three buttons at the
bottom: Save, Print and Close. Print and close is done by javascript. But
how
can I save the page on the client's computer? He/she could do this using
the
browser (file/save), but I need to have it done by pressing the
pushbutton.

In my serverside code I get the button-click-event, I also know how to get
data to the client (including file-save-dialog), but where can I get the
page's content?

The download code could look like this (with ??? being actually my
question):

Response.AddHeader("Content-Disposition", "attachment;
filename=Contract.html");
Response.AddHeader("Content-Length", ???.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Write(???);
Response.End();

Maybe I'm completely wrong and there is an other better way to do it.
Please
help!


Mar 2 '07 #4
@Aidy:

-"document.innerHTML or document.innerText or something"
What I am lookin for is 'or something'. I can't find an object which holds
the page's rendered content. I don't need images since there are no images on
the page, only formatted text (and three buttons).

-Wrong newsgroup
Why, and which would be right?

"Aidy" wrote:
Wrong newsgroup, but you can probably usee something like document.innerHTML
or document.innerText or something.

The problem with that is that it won't include images or anything included
etc. IE's client save is actually doing a lot of work.

"FreeNEasy" <Fr*******@community.nospamwrote in message
news:B1**********************************@microsof t.com...
Hello,

the scenario:

There's an ASPX page which shows some text and has three buttons at the
bottom: Save, Print and Close. Print and close is done by javascript. But
how
can I save the page on the client's computer? He/she could do this using
the
browser (file/save), but I need to have it done by pressing the
pushbutton.

In my serverside code I get the button-click-event, I also know how to get
data to the client (including file-save-dialog), but where can I get the
page's content?

The download code could look like this (with ??? being actually my
question):

Response.AddHeader("Content-Disposition", "attachment;
filename=Contract.html");
Response.AddHeader("Content-Length", ???.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Write(???);
Response.End();

Maybe I'm completely wrong and there is an other better way to do it.
Please
help!


Mar 2 '07 #5
Maybe you can call the SaveAs of the browser. For exemple IE :
http://www.codefoot.com/javascript/s...ke_saveas.html
Or send a stream (pdf for exemple).
"FreeNEasy" <Fr*******@community.nospama écrit dans le message de
news:B1**********************************@microsof t.com...
Hello,

the scenario:

There's an ASPX page which shows some text and has three buttons at the
bottom: Save, Print and Close. Print and close is done by javascript. But
how
can I save the page on the client's computer? He/she could do this using
the
browser (file/save), but I need to have it done by pressing the
pushbutton.

In my serverside code I get the button-click-event, I also know how to get
data to the client (including file-save-dialog), but where can I get the
page's content?

The download code could look like this (with ??? being actually my
question):

Response.AddHeader("Content-Disposition", "attachment;
filename=Contract.html");
Response.AddHeader("Content-Length", ???.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Write(???);
Response.End();

Maybe I'm completely wrong and there is an other better way to do it.
Please
help!
Mar 2 '07 #6
Hi FreeNEasy,

As some other members have provided some suggestion about retrieving page's
content, for example, use javascript DOM api to get the innerHTML of page
body.

#In Javascript I Want To Get The Page Source, And Store It In A Variable?
http://qa.techinterviews.com/q/20060731161006AAQncKe

The problem here is save the content to a file on client-side file system.
Generally, browser based web page application has natural security
restrictions on accessing client user's local resource(such as file system,
network, registry ....). Therefore, the default client-script code can not
create , modify or delete any file on the client system. To do this, you
need to either use windows script or activeX component which can leverage
strong code to do those privilege operations, however, this require the
client user to allow such strong code be executed in webbrowser. For your
scenario, I think this seems not quite convenient since you need to ask
every client user to adjust their client browser security setting.

Do you think it possible that you simply use a button to popup a help page
that demonstrate the steps for saving the a page in browser?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.



Mar 5 '07 #7
Hello,

Yes, saving to the client's computer directly is quite impossible as it runs
in a sandbox.
I think the only solution is sending a stream (document like pdf or
something else) and the user can clic "save as" or "open".

Maybe you can change the behaviour if you users are authenticated. You can
send it by email ?

Or you can format it in a printable version and put a "print" button (most
of the websites do this + email).

Ornette

"Steven Cheng[MSFT]" <st*****@online.microsoft.coma écrit dans le message
de news:Oj**************@TK2MSFTNGHUB02.phx.gbl...
Hi FreeNEasy,

As some other members have provided some suggestion about retrieving
page's
content, for example, use javascript DOM api to get the innerHTML of page
body.

#In Javascript I Want To Get The Page Source, And Store It In A Variable?
http://qa.techinterviews.com/q/20060731161006AAQncKe

The problem here is save the content to a file on client-side file system.
Generally, browser based web page application has natural security
restrictions on accessing client user's local resource(such as file
system,
network, registry ....). Therefore, the default client-script code can not
create , modify or delete any file on the client system. To do this, you
need to either use windows script or activeX component which can leverage
strong code to do those privilege operations, however, this require the
client user to allow such strong code be executed in webbrowser. For your
scenario, I think this seems not quite convenient since you need to ask
every client user to adjust their client browser security setting.

Do you think it possible that you simply use a button to popup a help page
that demonstrate the steps for saving the a page in browser?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.




Mar 5 '07 #8
Thanks for your input Ornette,

I think you've pointed out a good approach here. We can put a button on
the page which simply postback to server(or redirect to another page) that
will flush out the entire page content(document) as attachment mode. The
code logic in the postback event or another page should be as below:

**write all the document content into response stream

** change the response Content type as the proper one(csv or text or ...)

**add the attachment header such as
Response.AddHeader("Content-disposition", "attachment;
filename=FlatPDFForm.fdf");

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.


Mar 5 '07 #9
Thank you Ornette, thank you Steven,

the approach you suggested has come to my mind too. It's the very best
solution. Calling browser functions is always difficult because of browser
differences (IE, Firefox etc.).
**write all the document content into response stream
The only remaining problem I still have is, where/how (server side code) can
I get the document content? The ASPX page ist made of a form with text and
fields, how can I get the rendered content, I can't find it.
** change the response Content type as the proper one(csv or text or ...)
==>READY
**add the attachment header such as
Response.AddHeader("Content-disposition", "attachment;
filename=FlatPDFForm.fdf");
==>READY

Sincerely,
Michael

"Steven Cheng[MSFT]" wrote:
Thanks for your input Ornette,

I think you've pointed out a good approach here. We can put a button on
the page which simply postback to server(or redirect to another page) that
will flush out the entire page content(document) as attachment mode. The
code logic in the postback event or another page should be as below:

**write all the document content into response stream

** change the response Content type as the proper one(csv or text or ...)

**add the attachment header such as
Response.AddHeader("Content-disposition", "attachment;
filename=FlatPDFForm.fdf");

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.


Mar 5 '07 #10
Thanks for your reply Michael,

For your further question below:

The only remaining problem I still have is, where/how (server side code)
can
I get the document content? The ASPX page ist made of a form with text and
fields, how can I get the rendered content, I can't find it.
==================================================

So far based on my test, I have found the following two approachs:

1. just use the postback event(button click) in the same page, and add the
file download header in the postback event. e.g.

=====in page codebehind===
protected void btnSavePage_Click(object sender, EventArgs e)
{
this.Response.ContentType = "text/html";
this.Response.AddHeader("Content-Disposition", "attachment;
filename=output.htm");

}
==============
2. Or your can also try executing another page and flush the content of
another page into current page's response by Server.Execute method. e.g.

=====in another page================
protected void Page_Load(object sender, EventArgs e)
{

Response.ClearContent();

Server.Execute("~/accesspage.aspx");
Response.ContentType = "text/html";
Response.AddHeader("Content-Disposition", "attachment;
filename=output.htm");
Response.End();
}
=====================

Hope this also helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.


Mar 6 '07 #11
Thank you Steven,

this was the answer to my question.

I already tried approach #1, but made the mistake to add Response.End() at
the bottom, which resulted in an empty html-page.

MANY THANKS TO ALL WHO TRIED TO HELP ME.

Michael

"Steven Cheng[MSFT]" wrote:
Thanks for your reply Michael,

For your further question below:

The only remaining problem I still have is, where/how (server side code)
can
I get the document content? The ASPX page ist made of a form with text and
fields, how can I get the rendered content, I can't find it.
==================================================

So far based on my test, I have found the following two approachs:

1. just use the postback event(button click) in the same page, and add the
file download header in the postback event. e.g.

=====in page codebehind===
protected void btnSavePage_Click(object sender, EventArgs e)
{
this.Response.ContentType = "text/html";
this.Response.AddHeader("Content-Disposition", "attachment;
filename=output.htm");

}
==============
2. Or your can also try executing another page and flush the content of
another page into current page's response by Server.Execute method. e.g.

=====in another page================
protected void Page_Load(object sender, EventArgs e)
{

Response.ClearContent();

Server.Execute("~/accesspage.aspx");
Response.ContentType = "text/html";
Response.AddHeader("Content-Disposition", "attachment;
filename=output.htm");
Response.End();
}
=====================

Hope this also helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.


Mar 6 '07 #12
I also had to solve this problem and did use Steven's approach. It worked
great!

Now here is an interesting twist. The page that gets saved to the client
contains a several DataGrids components. The data displayed in the grids is
filtered by the contents of a separate drop down box. This allows the
client to "download" one page a time.

I now need to replace the drop down by a list box that support
multi-selects. When the client user clicks on the "download" button, I need
to generate several versions of the page, each displaying the data related
to one of the selections in the list box.

How do I do this?

I first tried to extend the approach given here ahd have the page render
itself several times. Each time it renders itself with new data, I would
capture the stream into a file on the server. Once we are done with all the
renderings, I would then zip up the files and send them to the client. The
question is, how can I force the page to render itself several times?

My next idea is to use a session variable to store all the selections from
the list box. I then create another page whose sole purpose is to redirect
me to my original page. In my original page, every time it loads, I check
the session variable and move on to the next item in the list. Once I
capture its output, I then redirect the response to the newly created page,
which will in turn send me back to my original page, etc.

Any ideas?
May 9 '07 #13

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

Similar topics

4
by: Mr Gordonz | last post by:
Hi All, I want to be able to save a file from the client's PC on the server. The tricky part is the aspx page is never actually seen by the user. Basically, I have a VB application running on...
3
by: Mr Gordonz | last post by:
Hi All, I am reposting this because I need some guidance/advice fairly quickly. I currently have the following setup for saving a file on the server: The user runs a VB app on his/her PC. ...
4
by: Nikhil Tayal | last post by:
Is there a way to write a file on the client machine from an aspx page? I've a custom query page and need to store the search criteria specified in an XML file on the user machine from my web page...
0
by: Dune | last post by:
Hi there, I have an aspx page that allows users to enter several parameters using drop downs and text boxes. The users then press a button that produces an extract based on the parameters they...
13
by: TomislaW | last post by:
I need page size of generated aspx page, how and when I can get this information programmatically
6
by: Michael Groeger | last post by:
Hi, I have an aspx page which generates an excel document and transfers it to the browser as attachment. Normally, once the document is transferred the open save dialog prompts to open or save...
0
by: Joseph I. Ceasar | last post by:
In an earlier post, someone asked about how to save a page on the client programmatically. I also had to solve this problem and did use Steven's approach. It worked great! Now here is an...
0
by: Joseph I. Ceasar | last post by:
In an earlier post, someone asked about how to save a page on the client programmatically. I also had to solve this problem and did use Steven's approach. It worked great! Now here is an...
4
by: moondaddy | last post by:
I have a htm page where I need to pass some data to an aspx page as a means of sending data to the database. I don't need to see the aspx page so I was going to put it in a hidden iframe. This...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.