Export to CSV : Not accepting characters

Last post 11-04-2009 6:11 AM by integrasol. 1 replies.

Sort Posts:

  • Export to CSV : Not accepting characters

    11-04-2009, 12:15 AM
    • Member
      52 point Member
    • jaishankar2704
    • Member since 05-17-2007, 7:20 AM
    • Hyderabad
    • Posts 237

    Hi I am using VB.Net 2005. I have MS-Office 2000 installed in my PC. After exporting to CSV from the application, I am unable to see special characters like ú, çã í, etc.  I have used the following Code  :

      Public Sub CreateCSVfile(ByVal dtable As DataTable, ByVal strFilePath As String)
            Dim sw As New StreamWriter(strFilePath, False)
            Dim icolcount As Integer = dtable.Columns.Count
            For i As Integer = 0 To icolcount - 1
                sw.Write(dtable.Columns(i))
                If i < icolcount - 1 Then
                    sw.Write(",")
                End If
            Next
            sw.Write(sw.NewLine)
            For Each drow As DataRow In dtable.Rows
                For i As Integer = 0 To icolcount - 1
                    If Not Convert.IsDBNull(drow(i)) Then
                        sw.Write(drow(i).ToString())
                    End If
                    If i < icolcount - 1 Then
                        sw.Write(",")
                    End If
                Next
                sw.Write(sw.NewLine)
            Next
            sw.Close()
        End Sub

     

    Is there any way to get special characters in CSV file?

    Thanks & Regards
    Jai
  • Re: Export to CSV : Not accepting characters

    11-04-2009, 6:11 AM
    Answer
    • Star
      8,278 point Star
    • integrasol
    • Member since 06-05-2009, 11:18 AM
    • Posts 1,572

    When instantiating the StreamWriter, use the constructor that takes the character encoding as a parameter, http://msdn.microsoft.com/en-us/library/f5f5x7kt.aspx, and then specify the correct encoding for your characters.

    Thanks

    Carsten

    Please click Mark as Answer if this post is of help to you. :-)



    My Blog
Page 1 of 1 (2 items)