473,769 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Save ASPX page on client programmaticall y

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.AddHea der("Content-Disposition", "attachment ;
filename=Contra ct.html");
Response.AddHea der("Content-Length", ???.Length.ToSt ring());
Response.Conten tType = "applicatio n/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 4775
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*******@comm unity.nospamwro te in message
news:B1******** *************** ***********@mic rosoft.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.AddHea der("Content-Disposition", "attachment ;
filename=Contra ct.html");
Response.AddHea der("Content-Length", ???.Length.ToSt ring());
Response.Conten tType = "applicatio n/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.innerH TML
or document.innerT ext 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*******@comm unity.nospamwro te in message
news:B1******** *************** ***********@mic rosoft.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.AddHea der("Content-Disposition", "attachment ;
filename=Contra ct.html");
Response.AddHea der("Content-Length", ???.Length.ToSt ring());
Response.Conten tType = "applicatio n/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*******@comm unity.nospamwro te in message
news:B1******** *************** ***********@mic rosoft.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.AddHea der("Content-Disposition", "attachment ;
filename=Contra ct.html");
Response.AddHea der("Content-Length", ???.Length.ToSt ring());
Response.Conten tType = "applicatio n/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.inner HTML or document.innerT ext 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.innerH TML
or document.innerT ext 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*******@comm unity.nospamwro te in message
news:B1******** *************** ***********@mic rosoft.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.AddHea der("Content-Disposition", "attachment ;
filename=Contra ct.html");
Response.AddHea der("Content-Length", ???.Length.ToSt ring());
Response.Conten tType = "applicatio n/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*******@comm unity.nospama écrit dans le message de
news:B1******** *************** ***********@mic rosoft.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.AddHea der("Content-Disposition", "attachment ;
filename=Contra ct.html");
Response.AddHea der("Content-Length", ???.Length.ToSt ring());
Response.Conten tType = "applicatio n/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******** ******@TK2MSFTN GHUB02.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(documen t) 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.AddHea der("Content-disposition", "attachment ;
filename=FlatPD FForm.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.AddHea der("Content-disposition", "attachment ;
filename=FlatPD FForm.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(documen t) 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.AddHea der("Content-disposition", "attachment ;
filename=FlatPD FForm.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

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

Similar topics

4
1671
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 the client PC, it calls an aspx page and passes some data as query srtings, including the full path to the relevant file(s) on the client PC. For example, the VB app might call the page thus: ...
3
1299
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. Among other things, the app prompts the user to select a file (or files). The app then uploads the file(s) to the web server (effectively pushing the files up). In addition, the app calls an aspx page and passes the file name (and a few other
4
4013
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 (aspx). I form the XML at run time from the search fileds specfied by the user and now my aspx page should save it on client machine so that the user can open the same query on next visit of the page. And help is appreciated. Nikhil
0
2979
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 entered. When this button is pressed and extract is prduced and IE's standard Open/Save dialog should popup so they can navigate to the directory to save the extract in, or if they want, they can choose to open and view the extract without saving it. ...
13
2155
by: TomislaW | last post by:
I need page size of generated aspx page, how and when I can get this information programmatically
6
2698
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 the excel document. When I click save I can save the excel document or when I click open it directly opens in excel. This works fine for all but one machine. On one machine however the dialog prompts to open or save the excel document (e.g....
0
962
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 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 list box. This allows the client to "download" one page a time.
0
1056
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 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 list box. This allows the client to "download" one page a time.
4
4164
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 works real good. Since I don't need the aspx page to do any postback, is there a way to pass a parameter to it with out it finishing the round trip back to the htm page? Thanks. -- moondaddy@newsgroup.nospam
0
9416
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10032
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9849
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8861
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7393
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5433
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3948
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2810
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.