Solved

VB.Net: UTF-8 Output Should Be ASCII

Posted on 2014-07-21
6
654 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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 62

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now