I think the error happens because Write CSV in UiPath doesn’t fully support Shift-JIS in our version. The reliable solution is to use Invoke Code with StreamWriter and Encoding.GetEncoding("shift_jis"). Other workarounds (registering CodePagesEncodingProvider or converting UTF-8) are less stable in Windows-Legacy.
Dim enc = System.Text.Encoding.GetEncoding(932) ' Shift-JIS
Function EscapeCsv(v As String) As String
If v Is Nothing Then Return ""
If v.Contains(","c) OrElse v.Contains(""""c) OrElse v.Contains(vbCr) OrElse v.Contains(vbLf) Then
v = v.Replace("""", """""")
Return """" & v & """"
End If
Return v
End Function
Using sw As New System.IO.StreamWriter(in_FilePath, False, enc)
' Header
sw.WriteLine(String.Join(",", in_DataTable.Columns.Cast(Of System.Data.DataColumn).Select(Function(c) EscapeCsv(c.ColumnName))))
' Rows
For Each r As System.Data.DataRow In in_DataTable.Rows
sw.WriteLine(String.Join(",", r.ItemArray.Select(Function(f) EscapeCsv(If(f, "").ToString()))))
Next
End Using
It is not tested because it is AI generated please try and do the modification if needed
Also make sure these are the Arguments in_DataTable (In, System.Data.DataTable) and in_FilePath (In, String)