Solved

VB.Net: UTF-8 Output Should Be ASCII

Posted on 2014-07-21
6
692 Views
Last Modified: 2014-07-21
Good Day Experts!

I have a little VB.Net application that uses the IO.StreamWriter to output data to  .CSV files that we send to the Client.

My feedback from them indicates the files are encoded in UTF-8 and that once converted to ASCII they were able to import.

I have never purposefully sent files encoded in any fashion.  Can you help me understand what I need to do in order to send them ASCII files so they don't have to convert them?

Thanks,
jimbo99999
0
Comment
Question by:Jimbo99999
6 Comments
 
LVL 6

Accepted Solution

by:
ksrsrinivasan earned 167 total points
ID: 40209346
You have to specify the encoding when you create the StreamWriter. Refer the constructor overload with encoding here
0
 
LVL 14

Assisted Solution

by:quizwedge
quizwedge earned 167 total points
ID: 40209366
Check out the StreamWriter constructor at http://msdn.microsoft.com/en-us/library/3aadshsx(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1 The second parameter is the encoding. You should be able to use System.Text.ASCIIEncoding.
0
 

Author Comment

by:Jimbo99999
ID: 40209388
Ok...thanks guys I appreciate the help sice I never did this before.

I will try now and report back.

Thanks,
jimbo99999
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Jimbo99999
ID: 40209409
I took a look at my code and am not sure how to integrate what you have shown me.

Here is what I have:

Public out As IO.StreamWriter
out = My.Computer.FileSystem.OpenTextFileWriter(FileName, False)
out.AutoFlush = True
out.WriteLine(HDRString)

Do I have to revise my style of coding to incorporate your suggestions?

Thanks again,
jimbo99999
0
 
LVL 6

Expert Comment

by:ksrsrinivasan
ID: 40209433
Replace
out = My.Computer.FileSystem.OpenTextFileWriter(FileName, False)

Open in new window

with
out = New StreamWriter(FileName, False, Encoding.ASCII)

Open in new window

0
 
LVL 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 166 total points
ID: 40209461
Hi jimbo99999;

Change this line :

out = My.Computer.FileSystem.OpenTextFileWriter(FileName, False)

To this :

out = My.Computer.FileSystem.OpenTextFileWriter(FileName, False, System.Text.Encoding.ASCII)

You could use at the end of that line System.Text.Encoding.Default because the default encoding using the third parameter is ASCII
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question