0
protected void Button2_Click1(object sender, EventArgs e)
        {
        StreamWriter myOutputStream = new StreamWriter("Myfile.csv");

        foreach (var item in urlLst.Items)
        {
            myOutputStream.WriteLine(item.ToString());
        }

        myOutputStream.Close();
    }

I am using this code but not getting output.

  • Have you tried specifying an absolute path? Also please provide more info on "not getting output" - any exception thrown? – vasek Dec 13 '17 at 08:47
  • Check this answer: https://stackoverflow.com/a/799454/1970317 – EvZ Dec 13 '17 at 08:47

1 Answers1

1
Hi You can try the below code sample.

            int items = 10; //ListBoxItems.Items.Count;
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < items; i++)
            {

                sb.AppendLine(i.ToString()); //Loop through and get list box item values
            }

            Response.Clear();
            Response.AddHeader("content-disposition", "attachment;filename=ListBox_Contents.csv");
            Response.Charset = "";
            Response.ContentType = "application/vnd.csv";
            StringWriter stringWrite = new StringWriter(sb);
            HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            Response.Write(stringWrite.ToString());
            Response.End();