String.Join format and how to break to a new line...

I have the following String.Join that I'm creating a csv export from but I'm having dificulty formating to a new line when it come the  Done By property String.Join(",", x1.StationActivity.SelectMany( y => y.ProductsUsed).Select(z => z.DoneBy))?? string.Empty,

I have included a screen shoot in what I'm trying to accomplish with my sample code.

           
                headerNames1.Add(ServiceAssistant.Tools.Language.Translate(Tools.Language.Keys.Product_Code, ViewBag));
                headerNames1.Add(ServiceAssistant.Tools.Language.Translate(Tools.Language.Keys.Description, ViewBag));
                headerNames1.Add(ServiceAssistant.Tools.Language.Translate(Tools.Language.Keys.Target, ViewBag));
                headerNames1.Add(ServiceAssistant.Tools.Language.Translate(Tools.Language.Keys.Done, ViewBag));
                var headers1 = String.Join(",", headerNames1.ToArray());

                sb.AppendLine(headers1);
                foreach (var x1 in (List<StationHistoryReportResults>)TempData["excsv"])

                {
                    var data1 = String.Join(",", new string[] {
                        //string.Format("\"{0}\"",item.B_Company),
                       
                      String.Join(",", x1.StationActivity.SelectMany( y => y.ProductsUsed).Select(z => z.ProductCode))?? string.Empty,
                      String.Join(",", x1.StationActivity.SelectMany( y => y.ProductsUsed).Select(z => z.ProductTranslatedDescription))?? string.Empty,
                      String.Join(",", x1.StationActivity.SelectMany( y => y.ProductsUsed).Select(z => z.Target))?? string.Empty,
                      String.Join(",", x1.StationActivity.SelectMany( y => y.ProductsUsed).Select(z => z.DoneBy))?? string.Empty,
                     });

                    sb.AppendLine(data1);

                }

                

                csv = sb.ToString();
                return File(new System.Text.UTF8Encoding().GetBytes(csv), "text/csv", "StationExportData.csv");
            }
            else

Open in new window


Captureexporttocsv.PNG
yguyon28Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Darrell PorterEnterprise Business Process ArchitectCommented:
After the
String.Join(",", x1.StationActivity.SelectMany( y => y.ProductsUsed).Select(z => z.DoneBy))?? string.Empty,

Open in new window

consider adding
String.Join("\n"),

Open in new window

Fabrice LambertConsultingCommented:
var data1 = String.Join(",", new string[] {
                        //string.Format("\"{0}\"",item.B_Company),
                       
    String.Join(",", x1.StationActivity.SelectMany( y => y.ProductsUsed).Select(z => z.ProductCode))?? string.Empty,
    String.Join(",", x1.StationActivity.SelectMany( y => y.ProductsUsed).Select(z => z.ProductTranslatedDescription))?? string.Empty,
    String.Join(",", x1.StationActivity.SelectMany( y => y.ProductsUsed).Select(z => z.Target))?? string.Empty,
    String.Join(",", x1.StationActivity.SelectMany( y => y.ProductsUsed).Select(z => z.DoneBy))?? string.Empty,
});

Open in new window

I'm no C# Expert, but when I see something like this ........ too many things done at once.
Maybe consider splitting this kind of expression into something more simple.

Writing code isn't only about achieving the desired results,  it is first about writing something understandable, that make sens, since the code is supposed to be readable by humans beeing.
yguyon28Author Commented:
I'm going to try this...

Add an empty space after sb.AppendLine(data1);?

i.e.

sb.Append(" ");
or maybe

sb.Append(Environment.NewLine);
Price Your IT Services for Profit

Managed service contracts are great - when they're making you money. Yes, you’re getting paid monthly, but is it actually profitable? Learn to calculate your hourly overhead burden so you can master your IT services pricing strategy.

yguyon28Author Commented:
no luck....
Fabrice LambertConsultingCommented:
Simplify your code so you clearly understand what is going on (as it stand, you don't !!), add more variables
toggle a breakpoint, and inspect your variables with the debugger.
yguyon28Author Commented:
Thank you for the advice.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.