Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Printing All My Pages

Printing All My Pages

Scheduled Pinned Locked Moved ASP.NET
databasecsharpsql-serversysadminquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dptalt
    wrote on last edited by
    #1

    My asp .net project has 18 pages. A user can fill out information on each of these pages. The information is stored in a SQL Server database. The administrator would like to click one button and automatically have all 18 pages print. How can this be done? Thanks in advance

    M S 2 Replies Last reply
    0
    • D dptalt

      My asp .net project has 18 pages. A user can fill out information on each of these pages. The information is stored in a SQL Server database. The administrator would like to click one button and automatically have all 18 pages print. How can this be done? Thanks in advance

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      Hi there. I am guessing a nicely formatted report that incorporates data from each of your 18 pages would probably be more desirable than a raw printout of each of 18 pages? or not? I would look to make an administrative reporting .aspx page that lays out the report data in a desirable format. Perhaps use Crystal Reports or SQL Reporting Services, or some other report tool to help. But if you are really interested in printing 18 raw .aspx pages, there would be a way to automate that. You could use the System.Net.WebClient class to retrieve html from a given Url, then parse that with a regular expression to retrieve <body> contents. Below is an example - you can see the potential issues with relative image and link locations, but if all pages were within the same application, that probably wouldn't be a problem. This is pretty quick and dirty too - if I were doing this for real, I might want to set up multiple threads to perform the url scraping. Again, all that said, I think I would first look at doing a nice administrative report layout.

      <%@ Page Language="C#" %>
      <%@ Import Namespace="System.Net" %>
      <%@ Import Namespace="System.Text.RegularExpressions" %>

      <script runat="server">

      string ScrapePageForBody(string sUrl)
      {
      // connect to the given URL, download the
      // html, and parse it for the <body> contents

      WebClient client = new WebClient();
      Byte\[\] buffer = client.DownloadData(sUrl);
      string sOutput = (new UTF8Encoding()).GetString(buffer);
      
      Regex rBody = new Regex(@"<body.\*>(?<content>\[\\s\\S\\w\\W\]\*)</body>", RegexOptions.IgnoreCase);
      Match m = rBody.Match(sOutput);
      if (m.Success)
          return m.Groups\["content"\].Value;
      else
          return "";
      

      }

      void Page_Load(object o, EventArgs e)
      {
      Page1Contents.Text = ScrapePageForBody("http://www.yahoo.com");
      Page2Contents.Text = ScrapePageForBody("http://www.CodeProject.com");
      }

      </script>

      <html>
      <head>
      <style>
      div.sample {border: 1px solid #CCCCCC; background-color: #EFEFEF;
      margin-top: 4px; margin-left: 10px; margin-right: 10px; margin-bottom: 20px;
      width:100%;
      padding: 10px;
      }
      </style>
      </head>

      <body>
      <form runat="server">

          <h2> Page 1:  www.yahoo.com</h2>
          <div class="sample">
      
      D 1 Reply Last reply
      0
      • D dptalt

        My asp .net project has 18 pages. A user can fill out information on each of these pages. The information is stored in a SQL Server database. The administrator would like to click one button and automatically have all 18 pages print. How can this be done? Thanks in advance

        S Offline
        S Offline
        Srinu_ss5
        wrote on last edited by
        #3

        (Optional) U can use Abcpdf to convert it into pdf file and print it :cool: Srinu

        1 Reply Last reply
        0
        • M Mike Ellison

          Hi there. I am guessing a nicely formatted report that incorporates data from each of your 18 pages would probably be more desirable than a raw printout of each of 18 pages? or not? I would look to make an administrative reporting .aspx page that lays out the report data in a desirable format. Perhaps use Crystal Reports or SQL Reporting Services, or some other report tool to help. But if you are really interested in printing 18 raw .aspx pages, there would be a way to automate that. You could use the System.Net.WebClient class to retrieve html from a given Url, then parse that with a regular expression to retrieve <body> contents. Below is an example - you can see the potential issues with relative image and link locations, but if all pages were within the same application, that probably wouldn't be a problem. This is pretty quick and dirty too - if I were doing this for real, I might want to set up multiple threads to perform the url scraping. Again, all that said, I think I would first look at doing a nice administrative report layout.

          <%@ Page Language="C#" %>
          <%@ Import Namespace="System.Net" %>
          <%@ Import Namespace="System.Text.RegularExpressions" %>

          <script runat="server">

          string ScrapePageForBody(string sUrl)
          {
          // connect to the given URL, download the
          // html, and parse it for the <body> contents

          WebClient client = new WebClient();
          Byte\[\] buffer = client.DownloadData(sUrl);
          string sOutput = (new UTF8Encoding()).GetString(buffer);
          
          Regex rBody = new Regex(@"<body.\*>(?<content>\[\\s\\S\\w\\W\]\*)</body>", RegexOptions.IgnoreCase);
          Match m = rBody.Match(sOutput);
          if (m.Success)
              return m.Groups\["content"\].Value;
          else
              return "";
          

          }

          void Page_Load(object o, EventArgs e)
          {
          Page1Contents.Text = ScrapePageForBody("http://www.yahoo.com");
          Page2Contents.Text = ScrapePageForBody("http://www.CodeProject.com");
          }

          </script>

          <html>
          <head>
          <style>
          div.sample {border: 1px solid #CCCCCC; background-color: #EFEFEF;
          margin-top: 4px; margin-left: 10px; margin-right: 10px; margin-bottom: 20px;
          width:100%;
          padding: 10px;
          }
          </style>
          </head>

          <body>
          <form runat="server">

              <h2> Page 1:  www.yahoo.com</h2>
              <div class="sample">
          
          D Offline
          D Offline
          dptalt
          wrote on last edited by
          #4

          Thanks for the code. My pages are formatted to print nicely from the browser so I think the automated way will work well... I think. The pages get their data from a database and the record in the database retrieved is determined by the value of a variable in the Load event in each page. Will I beable to assign a value to that variable when printing? Also, I'm using VB so I converted your sample code (not the script part), and it seems to work fine. The part I don't understand is where to put the script code into the project. I'm kind of new at asp. When I'm in the form designer and click on the Source tab does it go in there some where? Thanks again for your help!

          M 1 Reply Last reply
          0
          • D dptalt

            Thanks for the code. My pages are formatted to print nicely from the browser so I think the automated way will work well... I think. The pages get their data from a database and the record in the database retrieved is determined by the value of a variable in the Load event in each page. Will I beable to assign a value to that variable when printing? Also, I'm using VB so I converted your sample code (not the script part), and it seems to work fine. The part I don't understand is where to put the script code into the project. I'm kind of new at asp. When I'm in the form designer and click on the Source tab does it go in there some where? Thanks again for your help!

            M Offline
            M Offline
            Mike Ellison
            wrote on last edited by
            #5

            dptalt wrote:

            The pages get their data from a database and the record in the database retrieved is determined by the value of a variable in the Load event in each page. Will I beable to assign a value to that variable when printing?

            Well, if you build on the sample I showed you, you can create your own URL strings to incorporate a variable like that as part of the QueryString. That would be one way to pass a variable to your individual pages.

            dptalt wrote:

            The part I don't understand is where to put the script code into the project. I'm kind of new at asp. When I'm in the form designer and click on the Source tab does it go in there some where?

            Okay - this depends on whether your .aspx pages are using code-behind or not. If they are using code-behind, then for each .aspx page you'll have, you'll have a corresponding .vb page that contains the programming code. If you are not using code-behind, then you can put the programming code right on your .aspx page in a <script runat="server" > block. -- modified at 11:42 Wednesday 22nd February, 2006

            D 1 Reply Last reply
            0
            • M Mike Ellison

              dptalt wrote:

              The pages get their data from a database and the record in the database retrieved is determined by the value of a variable in the Load event in each page. Will I beable to assign a value to that variable when printing?

              Well, if you build on the sample I showed you, you can create your own URL strings to incorporate a variable like that as part of the QueryString. That would be one way to pass a variable to your individual pages.

              dptalt wrote:

              The part I don't understand is where to put the script code into the project. I'm kind of new at asp. When I'm in the form designer and click on the Source tab does it go in there some where?

              Okay - this depends on whether your .aspx pages are using code-behind or not. If they are using code-behind, then for each .aspx page you'll have, you'll have a corresponding .vb page that contains the programming code. If you are not using code-behind, then you can put the programming code right on your .aspx page in a <script runat="server" > block. -- modified at 11:42 Wednesday 22nd February, 2006

              D Offline
              D Offline
              dptalt
              wrote on last edited by
              #6

              I'm using a code-behind file. If I cut and paste your script example into the code window those squiggly lines appear indicating there are syntax errors. Is there a special place I need to put the script?

              M 1 Reply Last reply
              0
              • D dptalt

                I'm using a code-behind file. If I cut and paste your script example into the code window those squiggly lines appear indicating there are syntax errors. Is there a special place I need to put the script?

                M Offline
                M Offline
                Mike Ellison
                wrote on last edited by
                #7

                Hi there. Your code-behind file is defining a class (and remember, what I had was in C#, not VB). You could copy/paste the ScrapeBodyOfPage function pretty much as is, but you probably already have a Page_Load method in your class. So you would adapt what I wrote to your existing function (most likely). You would also use imports statements in your code-behind, rather than the <%@ Import %> directive that appears in the sample .aspx page I sent you.

                D 1 Reply Last reply
                0
                • M Mike Ellison

                  Hi there. Your code-behind file is defining a class (and remember, what I had was in C#, not VB). You could copy/paste the ScrapeBodyOfPage function pretty much as is, but you probably already have a Page_Load method in your class. So you would adapt what I wrote to your existing function (most likely). You would also use imports statements in your code-behind, rather than the <%@ Import %> directive that appears in the sample .aspx page I sent you.

                  D Offline
                  D Offline
                  dptalt
                  wrote on last edited by
                  #8

                  Hi. The part I don't understand is where to put the script code into the project. The part that start out with text . When I'm in the form designer and click on the Source tab does it go in there some where? And if so where does it go? Or since I have a code-behind file can I put the script code there instead? And if so do I make a new function for it? Also, where in your example does it do the printing? Thanks for all your help!

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups