Reputation: 1840
I have a DataTable, dt
that I want to email to a user as a CSV file. The existing emailing workflow involves adding the file to an attachments
table and then the emailing function will pull the file from there. For now, I'm bypassing teh email part and downloading the file directly using the ID and a function that works for all the other files in the table (which includes csv and xls). The problem is that everything I've tried for adding the DataTable as a file to this table will be downloaded as random Unicode characters.
What I've tried:
System.Text.Encoding.ASCII.GetBytes(attachmentCSV)
to make a byte[]
I'm not finding anything else helpful through my searching, so I'm at a loss at what to try next. How can I take a DataTable and save it into a SQL table as a file (csv, xls, any spreadsheet format that Excel will open)? Ideally, I'd like a way that avoids saving the file to disk first.
Upvotes: 0
Views: 174
Reputation: 1840
This problem lies in the software being used to open the file, LibreOffice. The character set was being set to UTF-16 instead of UTF-8. Changing the set appears to fix the problem.
Upvotes: 1