Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Save ASPX page on client programmatically (http://www.velocityreviews.com/forums/t419481-save-aspx-page-on-client-programmatically.html)

=?Utf-8?B?RnJlZU5FYXN5?= 03-02-2007 01:49 PM

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!

Aidy 03-02-2007 02:44 PM

Re: Save ASPX page on client programmatically
 
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" <FreeNEasy@community.nospam> wrote in message
news:B17FA360-4E60-41EA-A6F3-BC6CA159DF87@microsoft.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!




Norman Yuan 03-02-2007 02:44 PM

Re: Save ASPX page on client programmatically
 
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" <FreeNEasy@community.nospam> wrote in message
news:B17FA360-4E60-41EA-A6F3-BC6CA159DF87@microsoft.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!




=?Utf-8?B?RnJlZU5FYXN5?= 03-02-2007 03:41 PM

Re: Save ASPX page on client programmatically
 
@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" <FreeNEasy@community.nospam> wrote in message
> news:B17FA360-4E60-41EA-A6F3-BC6CA159DF87@microsoft.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!

>
>
>


=?Utf-8?B?RnJlZU5FYXN5?= 03-02-2007 03:46 PM

Re: Save ASPX page on client programmatically
 
@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" <FreeNEasy@community.nospam> wrote in message
> news:B17FA360-4E60-41EA-A6F3-BC6CA159DF87@microsoft.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!

>
>
>


Ornette 03-02-2007 08:38 PM

Re: Save ASPX page on client programmatically
 
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" <FreeNEasy@community.nospam> a écrit dans le message de
news:B17FA360-4E60-41EA-A6F3-BC6CA159DF87@microsoft.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!



Steven Cheng[MSFT] 03-05-2007 02:08 AM

Re: Save ASPX page on client programmatically
 
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.












Ornette 03-05-2007 03:11 AM

Re: Save ASPX page on client programmatically
 
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]" <stcheng@online.microsoft.com> a écrit dans le message
de news:Oj9p3ssXHHA.2508@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.
>
>
>
>
>
>
>
>
>
>
>



Steven Cheng[MSFT] 03-05-2007 04:53 AM

Re: Save ASPX page on client programmatically
 
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.





=?Utf-8?B?RnJlZU5FYXN5?= 03-05-2007 08:40 AM

Re: Save ASPX page on client programmatically
 
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.
>
>
>
>
>



All times are GMT. The time now is 05:08 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.