-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDefault.aspx.vb
69 lines (62 loc) · 3.09 KB
/
Default.aspx.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Net
Imports System.Web.UI
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
Public Partial Class _Default
Inherits Page
Private documentServer As RichEditDocumentServer = Nothing
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
documentServer = New RichEditDocumentServer()
If Request.QueryString.Count > 0 AndAlso Request.QueryString(0).StartsWith("preview") Then
RefreshPreview(Request.QueryString(0))
End If
End Sub
Private Sub RefreshPreview(ByVal previewName As String)
Response.StatusCode = CInt(HttpStatusCode.OK)
Response.ContentType = "text/html"
Dim outputStream As Stream = ExecuteMerge(previewName, DocumentFormat.Html)
outputStream.Seek(0, SeekOrigin.Begin)
Copy(outputStream, Response.OutputStream)
Response.End()
End Sub
Private Function ExecuteMerge(ByVal templateName As String, ByVal documentFormat As DocumentFormat) As Stream
Dim result As Stream = New MemoryStream()
Dim mailMergeOptions As MailMergeOptions = documentServer.CreateMailMergeOptions()
If Equals(templateName, "preview1") Then
documentServer.LoadDocument(Page.MapPath("~/App_Data/InvoicesDetail.rtf"))
Dim invoices As List(Of Invoice) = New List(Of Invoice)(10)
invoices.Add(New Invoice(0, "Invoice1", 10.0D))
invoices.Add(New Invoice(1, "Invoice2", 15.0D))
invoices.Add(New Invoice(2, "Invoice3", 20.0D))
mailMergeOptions.DataSource = invoices
ElseIf Equals(templateName, "preview2") Then
documentServer.LoadDocument(Page.MapPath("~/App_Data/SamplesDetail.rtf"))
mailMergeOptions.DataSource = ManualDataSet.CreateData().Tables(0)
ElseIf Equals(templateName, "all") Then
Dim part1 As Stream = ExecuteMerge("preview1", documentFormat)
Dim part2 As Stream = ExecuteMerge("preview2", documentFormat)
part1.Seek(0, SeekOrigin.Begin)
part2.Seek(0, SeekOrigin.Begin)
documentServer.LoadDocument(part1, documentFormat)
documentServer.Document.AppendDocumentContent(part2, documentFormat)
documentServer.SaveDocument(result, documentFormat)
Return result
End If
documentServer.Options.Export.Html.EmbedImages = True
mailMergeOptions.MergeMode = MergeMode.JoinTables
documentServer.MailMerge(mailMergeOptions, result, documentFormat)
Return result
End Function
Protected Sub btnDownload_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim outputStream As Stream = ExecuteMerge("all", DocumentFormat.Rtf)
outputStream.Seek(0, SeekOrigin.Begin)
Copy(outputStream, Response.OutputStream)
Response.StatusCode = CInt(HttpStatusCode.OK)
Response.ContentType = "application/rtf"
Response.AddHeader("Content-Disposition", "attachment; filename=RichEditMailMerge.rtf")
Response.End()
End Sub
End Class