Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 12th, 2005, 01:09 PM
Authorized User
 
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I get html of current page?

I have a webform with a bunch of controls on it. I want to make a button that will save the page to a static place on my machine. I need to know how to get the html code for the current page so i can write it to a file.

pretty much a button on the form that does the same thing as the save as button in IE browser, except I am going to write in the location rather then the user.

thanks
Michael Hsu

 
Old May 12th, 2005, 01:45 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I don' think you'll be able to do this. What you are asking (in more generalized terms) is, "How do I write client-side script that allows me to write to the user's hard drive." This would be a major security risk if it was capable of happening. You'll have to write some kind of client-side control (activeX, java applet) that would be embedded into the page to do this.

Depending on what you expect the client audience to be, you might be able to do this with some other client-side scripting, like VBScript (if you're in IE) but I still think there will be serious limitations. Supporting this kind of capability leaves way too much open for malicious code.

-Peter
 
Old May 12th, 2005, 02:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

For making forms on the fly like this- you will want to look into Infopath.


{EDIT} I should add that Adobe has some pretty nice forms handling things also, using PDF's.. you might want to look into that.



Hal Levy
I am here to help you, not do it for you.
That is, unless you hire me. I am looking for work.
 
Old May 12th, 2005, 03:00 PM
Authorized User
 
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think you guys misunderstood my question.

I have a .aspx file that is in a certain format. I want to save that file locally and then covert it to a pdf which the user will be prompted to save that somewhere on their harddrive.

is that not possible?
I want to save the display as an html file that will be converted to a pdf.

 
Old May 12th, 2005, 03:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

No.

Create the PDF on the server, then send it over to the user in the browser- where then can easily save it from the client.


Hal Levy
I am here to help you, not do it for you.
That is, unless you hire me. I am looking for work.
 
Old May 12th, 2005, 03:47 PM
Authorized User
 
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ya I'm going to create the PDF on the server and send it over, but I have to create the PDF based on something. I don't think I can create it from the web form so on the server side I want to save the page in html and then conver that to pdf, save it on the server, then send it over.

I want to make a html file based on what the webform is displaying.

Michael Hsu

 
Old May 12th, 2005, 03:59 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I don't think there is an (easy) way to get at the final HTML of the page (there may be ways, possibly using HttpHandlers maybe, or some other post loading events, but this will be difficult to implement).

However, you could recreate the entire page on the fly in memory. Instead of, say, adding a DataGrid to the ASPX portion of the page, you can create one on the fly and bind your data to it. Then you can use the following method to get the control's HTML in a string:
Code:
    public static string GetHtmlFromControl(Control aControl)
    {
      // Get the rendered HTML of a control
      StringBuilder SB = new StringBuilder();
      StringWriter SW = new StringWriter(SB);
      HtmlTextWriter htmlTW = new HtmlTextWriter(SW);
      aControl.RenderControl(htmlTW);
      return SB.ToString();
    }
    I use this method quite a lot to send nicely formatted Html e-mail for error logging, shopping carts etc.

Check out the following article for more details: http://aspnet.4guysfromrolla.com/articles/091102-1.aspx

(My method is comes from this article).

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old May 12th, 2005, 04:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

What Imar said.

Hal Levy
I am here to help you, not do it for you.
That is, unless you hire me. I am looking for work.
 
Old May 12th, 2005, 04:27 PM
Authorized User
 
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

okay thanks guys

Michael Hsu






Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a GroupHeading in the current page dlamarche Access VBA 0 October 11th, 2008 12:57 AM
Emailing current page toma12 ASP.NET 2.0 Professional 1 November 29th, 2006 12:31 PM
Redirect to new page without closing current page peter2004 ASP.NET 2.0 Basics 5 June 5th, 2006 08:49 PM
print page that is not the current page crmpicco Javascript How-To 0 July 26th, 2005 09:11 AM
reference of prev. page in current page kasanar ASP.NET 1.0 and 1.1 Professional 1 February 13th, 2005 02:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.