Solved

VB.Net: UTF-8 Output Should Be ASCII

Posted on 2014-07-21
6
669 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expando 4 47
How to open a link from vb.net app 3 23
I need help embedding an image as HTML in my vb.net application 3 50
Help with AsEnumerable(), LINQ 4 22
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 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

13 Experts available now in Live!

Get 1:1 Help Now