Solved

VB.Net: UTF-8 Output Should Be ASCII

Posted on 2014-07-21
6
703 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

697 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