2012-09-17 30 views
0

我對此有所瞭解,但已經有了一個生成腳本到ics文件,爲iCal和Outlook工作100%,但我無法看到我如何修復編碼。當我在我的數據庫中有北歐版的文本(æ&)時,那麼我得到的字母是? 有人可以幫我設置這個使用iso-8859-1。當我生成一個ics文件時,顯示nordicæøå(æøå)

或者我需要使用6代替代碼來代替帶有html標籤的字母(æ&)!

我的代碼是

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 

回答

0

您寫這封信是用ASCIIEncoding它映射存在問題的字符到流「?」。

您可以修復您的代碼,使其對這種錯誤性做了一些修改:

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)) 
+0

如果我使用該代碼的話,我現在得到這些標籤¯E Y –

+0

也許你需要使用UTF-8編碼。要解決這個問題,你可以使用像Fiddler這樣的工具來查看從服務器收到的實際字節數。例如對於ISO-8859-1字符串,應該將字符串編碼爲0xE6 0xF8 0xE5,並且將其編碼爲0xAF 0xCA 0xFF,這是完全不同的。 –

+0

!???嗯嗯,但它的工作;)THX –

相關問題