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

  • Home
  • SEARCH
  • 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 8077013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:23:12+00:00 2026-06-05T15:23:12+00:00

One of my action outputs a csv file. The problem is if a field

  • 0

One of my action outputs a csv file. The problem is if a field contains comma, then it splits the datarow into two fields. I tried using “\”” to include each row in double quotes but this is not working. Could someone guide me in the right direction?

UPDATE

var sw = new StringWriter();
            sw.WriteLine(String.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13}", "First Name","Last Name","Address1","Address2","City","State","Postal Code","Country","Dealer ID","Dealer Name","Survey Source","Amount","Email","Survey Code"));
            sw.WriteLine(String.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\",\"{6}\",\"{7}\",\"{8}\",\"{9}\",\"{10}\",\"{11}\",\"{12}\",\"{13}\"",  model.SurveyWinnerDetails.Select(p => p.FirstName).First().Replace("\"", "\"\""),
                        model.SurveyWinnerDetails.Select(p => p.LastName).First().Replace("\"", "\"\""),
                        model.SurveyWinnerDetails.Select(p => p.Address1).First().Replace("\"", "\"\""),
                        model.SurveyWinnerDetails.Select(p => p.Address2).First().Replace("\"", "\"\""),
                        model.SurveyWinnerDetails.Select(p => p.City).First().Replace("\"", "\"\""),
                        model.SurveyWinnerDetails.Select(p => p.State).First().Replace("\"", "\"\""),
                        model.SurveyWinnerDetails.Select(p => p.PostalCode).First().Replace("\"", "\"\""),
                        model.SurveyWinnerDetails.Select(p => p.CountryCode).First().Replace("\"", "\"\""),
                        model.SurveyWinnerDetails.Select(p => p.DealerID).First().Replace("\"", "\"\""),
                        model.SurveyWinnerDetails.Select(p => p.DealerName).First().Replace("\"", "\"\""),
                        model.SurveyWinnerDetails.Select(p => p.SurveySource).First().Replace("\"", "\"\""),
                        model.SurveyWinnerDetails.Select(p => p.Amount).First().Replace("\"", "\"\""),
                        model.SurveyWinnerDetails.Select(p => p.Email).First().Replace("\"", "\"\""),
                        model.SurveyWinnerDetails.Select(p => p.SurveyCode).First().Replace("\"", "\"\"")));
            return File(new System.Text.UTF8Encoding().GetBytes(sw.ToString()), "text/csv", "SurveyWinner.csv");

When i run this now, I get an error: Object reference not set to the instance of an object.

  • 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-05T15:23:13+00:00Added an answer on June 5, 2026 at 3:23 pm

    There’s no one “official” CSV format, though the most common is outlined in RFC 4180 (http://tools.ietf.org/html/rfc4180). According to that RFC (section 6), fields containing commas should be enclosed in double quotes.

    Per @Axam’s observation below, RFC 4180 does not allow for extra whitespace around the commas. Change your format string to:

    "{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13}"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get java to perform one action after one click and then
Okay, when my app starts it has two tabs, and one action in the
I have one custom action (add) and two custom objects (favorites list) and (tv
We've been trying to redirect from one action to another, hoping that data would
Is it possible to clear one action's cache from another action? Let's say my
I want to route to more than one action, I make the routing configuration
Is there a way to indent/tab multiple lines in one action in the Codegear
Right now I have a single sound playing from one action, button press, accelerometer,
I'd like to be able to dispatch from one controller action to another conditionally,
I have two forms in one view updating the User Profile. One Form is

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.