Forum: ASP.NET2.0 |
Thema:
AW: AW: AW: AW: AW: AW: AW: AW: AW: Seriendruck aus Anwendung starten |
Von:
Thomas Hauser (
08.08.2007 18:13) |
Logisch!!!
<%@ WebHandler Language="VB" Class="PrintVb" %>
Imports System
Imports System.Web
Public Class PrintVb : Implements IHttpHandler
Private templateFile As String = "Default.html"
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "text/html"
If (Not String.IsNullOrEmpty(context.Request.QueryString("template"))) Then
Me.templateFile = context.Request.QueryString("template")
End If
Dim con As New System.Data.SqlClient.SqlConnection()
con.ConnectionString = "Data Source=.;Initial Catalog=aspnetdb;Integrated Security=true"
con.Open()
Dim cmd As New System.Data.SqlClient.SqlCommand()
cmd.Connection = con
cmd.CommandText = "select * from test"
Dim table As New System.Data.DataTable("data")
table.Load(cmd.ExecuteReader())
con.Close()
Dim template As String = ""
Using sr As New System.IO.StreamReader(context.Server.MapPath("~/App_Data/templates/" + Me.templateFile))
template = sr.ReadToEnd()
sr.Close()
End Using
Dim sb As New System.Text.StringBuilder()
For Each row As System.Data.DataRow In table.Rows
Dim page As String = template
For Each col As System.Data.DataColumn In table.Columns
page = page.Replace(String.Format("%%{0}%%", col.ColumnName), row(col).ToString())
Next
sb.AppendLine(page)
Next
context.Response.Write(sb.ToString())
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
Thomas Hauser (Trainer und Consultant, Blog: http://thomashauser.spaces.live.com, Forum: http://www.sharepointbook.de - Die Forum-Webseite zum Buch!)
Antworten
Vorsicht bei der Eingabe: Die Zeichen ' oder -- sind nicht erlaubt!