String encoding error when reading file

Posted on 2011-10-21
Last Modified: 2012-05-12
Hello Experts,

When I upload the attached file and compare the "LastName" to an existing value in the database, I get that the strings are not equal. When I debug in visual studio, I get a question mark inside a diamond shape. I understand I probably need to encode the csv file string, but I am not sure how to go about this.


Also, assume I have a working csv parser.  SpecialCharacter.csv
Question by:freezegravity
    LVL 17

    Accepted Solution

    Hello, your file is in ANSI encoding, try this:
    using (System.IO.StreamReader sr = new System.IO.StreamReader(@"C:\SpecialCharacter.csv", System.Text.Encoding.GetEncoding(1252)))
        string s = sr.ReadToEnd();

    Open in new window

    LVL 17

    Expert Comment

    by:Carlos Villegas

    Author Closing Comment

    Thanks a lot. Turns out I wasn't sending the Encoding parameter into my streamreader and as soon as I did that, things started to work. Also, the link in your second comment helped me understand this thing slightly better.
    LVL 17

    Expert Comment

    by:Carlos Villegas
    Glad to help!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now