我对此很陌生,但是有一个生成 ics 文件的脚本,可以 100% 地为 iCal 和 Outlook 工作,但我看不出我是如何修复编码的。
当我的数据库中有一个带有北欧 æ ø å (æ ø å) 的文本时,我得到的字母为 ?。有人可以帮我设置它以使用 iso-8859-1。
或者我是否需要制作 6 个替换代码,用 html-tag (æ ø å) 替换字母!?
我的代码是
Imports System.Data.OleDb
Imports System.Data
Imports RF.Event2
Partial Class _new
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
End If
End Sub
Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ical As New iCalendar()
Dim strConnection As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString)
Dim strQuery As String = String.Empty
strQuery = "SELECT * FROM [Events] WHERE ([EventType]='K' OR [EventType]='E' OR [EventType]='T') ORDER BY [EventDate] ASC"
Dim daEvents As New OleDbDataAdapter(strQuery, strConnection)
Dim dtEvents As New DataTable
strConnection.Open()
daEvents.Fill(dtEvents)
strConnection.Close()
If (dtEvents.Rows.Count > 0) Then
For i As Integer = 0 To dtEvents.Rows.Count - 1
Dim ev As New [Event]()
ev.Title = dtEvents.Rows(i)("EventHome")
ev.Description = dtEvents.Rows(i)("EventNote")
ev.Location = dtEvents.Rows(i)("EventPlace")
ev.StartTime = DateTime.Parse(dtEvents.Rows(i)("EventDate"))
ev.EndTime = DateTime.Parse(dtEvents.Rows(i)("EventDate").AddMinutes(90))
ical.Events.Add(ev)
Next
End If
' Set the content-type of the response and file name
' so Windows knows how to handle the response.
Context.Response.Buffer = True
Context.Response.ContentType = "text/calendar"
Context.Response.ContentEncoding = Encoding.GetEncoding("iso-8859-1")
Context.Response.Charset = "iso-8859-1"
Context.Response.AddHeader("content-disposition", "inline;filename=Sport.ics")
' Write the bytes of the iCalendar item output to the resonse stream
Context.Response.BinaryWrite(New System.Text.ASCIIEncoding().GetBytes(ical.Output))
Context.Response.[End]()
'Dim enc As System.Text.Encoding = System.Text.Encoding.GetEncoding("iso-8859-1")
End Sub
End Class