protected void btnExport_Click(object sender, EventArgs e){string path1 = HttpContext.Current.Server.MapPath(\". \") + \"\\\\3_StuInfo.txt\";string path = Server.MapPath(\"~/2_District.txt\");StreamWriter sw = new StreamWriter(path);try{sw.WriteLine(string.Format(\"{0}的{1}下辖{2}个县区:\", ddlProvince.SelectedItem.Text, ddlCity.SelectedItem.Text, ddlDistrict.Items.Count));foreach (ListItem item in ddlDistrict.Items){sw.WriteLine(string.Format(\"{0}(ID={1})\", item.Text, item.Value));}}catch (Exception error){labTips.Text = \"导出失败请重试\";}finally {sw.Close();labTips.Text = \"导出数据成功!\";}}
要点
创建数据流
StreamWriter sw = new StreamWriter(path);
写入数据
sw.WriteLine();
关闭流
sw.Close();
爱站程序员基地
![(原创)[C#] 一步一步自定义拖拽(Drag&Drop)时的鼠标效果:(一)基本原理及基本实现-爱站程序员基地](https://aiznh.com/wp-content/uploads/2022/07/20220721231016-62d9dcd85c40b-220x150.gif)

