Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7849907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:40:54+00:00 2026-06-02T18:40:54+00:00

Having an problem where streamwriter is producing erroneous characters in a csv that I’m

  • 0

Having an problem where streamwriter is producing erroneous characters in a csv that I’m producing. The characters,  , only appear at the start of the file:

5,"GEN",555555555,,"Evan","Smith",,,,,,,,,,,,,,,,,,,,,,,,,"email@someplace.com"
5,"GEN",555555555,,"Dorathy","Smith",,,,,,,,,,,,,,,,,,,,,,,,,"email@someplace.com"
5,"GEN",555555555,,"Marvin","Smith",,,,,,,,,,,,,,,,,,,,,,,,,"email@someplace.com"
....

Looks to me like an encoding problem. I’ve tried different encoding and also a regex to clean the string with little luck. Here’s the code for preview (although it’s nothing complex). Also it’s running as a web process.

string fileName = includeEmail == false ? "attachment; filename=stuacct_batch.txt" : "attachment; filename=rentals.csv";
Context.Response.Clear();
Context.Response.AddHeader("content-disposition", fileName);
Context.Response.ContentType = includeEmail == false ? "text/plain" : "text/csv";

using (StreamWriter sw = new StreamWriter(Response.OutputStream, Encoding.UTF8))
{   
    string line = "";
    foreach (Student s in students)
    {
        // ... some logic above that that's misc. to this problem 
        line = "5,\"GEN\"," + s.StudentNumber + ",,\"" + s.FirstName + "\",\"" + s.LastName + "\",,,,,,,,,,,,,,,,,,,,,,,,,\"" + s.Email + "\"";
        sw.WriteLine(line);
    }
}

Context.Response.End();
Context.Response.Flush();
Context.ApplicationInstance.CompleteRequest();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:40:55+00:00Added an answer on June 2, 2026 at 6:40 pm

    You have specified that you want to use UTF-8 encoding for the stream and those initial bytes is a valid UTF-8 Byte Order Mark (BOM). The problem is apparently that your viewer/editor doesn’t decode the UTF-8 stream correctly. If it only is the BOM that is the problem and you want to create a stream without a BOM you can create your own instance of the UTF8Encoding class:

    var encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
    using (StreamWriter sw = new StreamWriter(Response.OutputStream, encoding)) ...
    

    In case you really want to work with ASCII data you should use that encoding instead:

    using (StreamWriter sw = new StreamWriter(Response.OutputStream, Encoding.ASCII)) ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a major problem with writing values into a new CSV file. I
I'm having a problem writing Norwegian characters into an XML file using C#. I
I having problem using CHCSVwriter to export my arrays to CSV or excel file.
I am having problem that when i am trying to submit the form by
having problem with null pointer exception and i read few article bout that error
I having problem with file download, I am able to download file in emulator
C#.NET 4.0 I'm having an interesting problem here with reading a custom file archive
Having problem with jquery submit(). The problem is that it doesn't work on the
I am having difficulties figuring out what is causing wierd characters to appear in
I'm having problem reading from a plist file I have the Settings.plist file saved

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.