生成ics文件时,无法显示北欧æø(æøå)

时间:2012-09-17 08:36:39

标签: asp.net vb.net ado.net outlook icalendar

我是新手,但是有一个生成脚本到ics文件,为iCal和Outlook 100%工作,但我无法看到我如何修复编码。

当我在我的数据库中有一个带有北欧æøå(æøå)的文本时,我得到的字母是? 有人可以帮我设置使用iso-8859-1。

或者我是否需要使用html-tag(æøå)制作6替换代码的替换代码!?

我的代码是

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

1 个答案:

答案 0 :(得分:0)

您正在使用ASCIIEncoding写入流,将有问题的字符映射为“?”。

你可以修改你的代码并使其能够对这个bug进行一些修改:

Context.Response.ContentEncoding = Encoding.GetEncoding("iso-8859-1") 
Context.Response.Charset = Context.Response.ContentEncoding.WebName
Context.Response.AddHeader("content-disposition", "inline;filename=Sport.ics") 

' Write the bytes of the iCalendar item output to the resonse stream 
Context.Response.BinaryWrite(Context.Response.ContentEncoding.GetBytes(ical.Output))