-
Notifications
You must be signed in to change notification settings - Fork 2
/
Default.aspx.vb
53 lines (48 loc) · 1.91 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
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Web
Imports System.Web.Script.Services
Imports System.Web.Services
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace RichWebForms
Partial Public Class [Default]
Inherits System.Web.UI.Page
Public InitialDocument As String
Private Const documentFolderPath = "~/App_Data/"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
InitialDocument = Convert.ToBase64String(System.IO.File.ReadAllBytes(
Server.MapPath($"{documentFolderPath}template.docx")))
End Sub
<WebMethod, ScriptMethod(UseHttpGet:=True)>
Public Shared Function GetDataSource() As IEnumerable(Of Hashtable)
Dim personId As Integer = 0
Dim data = {"John", "Piter", "Mark"}.Select(Function(name) New Hashtable() From {
{"FirstName", name},
{"Id", personId}
}).ToList()
personId += 1
Return data
End Function
<WebMethod>
Public Shared Sub Export(ByVal base64 As String, ByVal fileName As String, ByVal format As Integer, ByVal reason As String)
Dim fileContent() As Byte = Convert.FromBase64String(base64)
Dim path As String = Hosting.HostingEnvironment.MapPath($"{documentFolderPath}{fileName}.{GetExtension(format)}")
File.WriteAllBytes(path, fileContent)
End Sub
Private Shared Function GetExtension(ByVal format As Integer) As String
Select Case format
Case 4
Return "docx"
Case 3
Return "rtf"
Case 1
Return "txt"
End Select
Return "docx"
End Function
End Class
End Namespace