c# - How to convert a string array to a csv

String array to csv
convert-string-array-to-csv.aspx

<%@ Page Language="C#" AutoEventWireup="true"%>
<%@ Import Namespace="System.IO" %>
    
<!DOCTYPE html>    
<script runat="server">  
    protected void Button1_Click(object sender, System.EventArgs e)    
    {  
        string[] colors = new string[]  
        {  
            "red",  
            "green",  
            "yellow",  
            "blue",  
            "pink",  
        };  
  
        Label1.Text = "colors array.........<br />";
        foreach (string s in colors)  
        {  
            Label1.Text += s + "<br />";  
        }

        string commaseparatedstring = String.Join(",", colors);
        string filename = Server.MapPath("csv.txt");

        using (StreamWriter file = new StreamWriter(filename))
        {
            file.Write(commaseparatedstring);
        }
    }    
</script>    
    
<html xmlns="http://www.w3.org/1999/xhtml">    
<head id="Head1" runat="server">    
    <title>c# example - string array to csv</title>    
</head>    
<body>    
    <form id="form1" runat="server">    
    <div>    
        <h2 style="color:DarkBlue; font-style:italic;">    
            c# example - string array to csv
        </h2>    
        <hr width="550" align="left" color="LightBlue" />      
        <asp:Label     
            ID="Label1"     
            runat="server"    
            Font-Size="Large"    
            >    
        </asp:Label>    
        <br /><br />  
        <asp:Button     
            ID="Button1"     
            runat="server"     
            Text="convert string array to csv"    
            OnClick="Button1_Click"  
            Height="40"    
            Font-Bold="true"    
            />    
    </div>    
    </form>    
</body>    
</html>
More c# examples