日期:2014-05-18 浏览次数:20486 次
protected void Button1_Click(object sender, EventArgs e) { string path = Server.MapPath(("init_" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + ".txt")); //FileStream fsobj = new FileStream(path, FileMode.OpenOrCreate); StreamWriter sw = new StreamWriter(path,true, System.Text.UnicodeEncoding.Unicode); SqlDataAdapter da = new SqlDataAdapter(sql, myConnection); DataSet ds = new DataSet(); da.Fill(ds); DataTable dt = ds.Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { sw.Write(dt.Rows[i]["userID"].ToString().Trim() + "," + dt.Rows[i]["userName"].ToString().Trim() + "," + dt.Rows[i]["Address"].ToString().Trim() + "," + dt.Rows[i]["Telphone"].ToString().Trim() + "\r\n"); } sw.Close();
<input name=Button onClick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为> <OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
------解决方案--------------------
private void ExportTXT() { string str_File=""; string strconn= ConfigurationSettings.AppSettings["dsn"]; SqlConnection cn=new SqlConnection(strconn); string s_temp="select applypernum ,starttime ,endtime,leavemode,leavehour from temptable order by tempedi"; string SaveFileName=DL1.SelectedItem.Text.ToString(); SaveFileName=SaveFileName+".txt"; try { cn.Open(); SqlCommand cmtemp=new SqlCommand(s_temp,cn); SqlDataReader drtemp=cmtemp.ExecuteReader(); while(drtemp.Read()) { str_File=str_File+drtemp["applypernum"].ToString(); str_File=str_File+drtemp["starttime "].ToString; ........ str_File=str_File+"\r\n"; } if(File.Exists("c:\\"+SaveFileName)) { Label1.Text="该文件已经存在!已经被删除,请重新再次导出即可"; File.Delete("c:\\"+SaveFileName); return; } else { StreamWriter sw=File.CreateText("c:\\"+SaveFileName); //创建文本文件 sw.WriteLine(str_File); sw.Close(); Label1.Text="写入文件成功!"; } } catch(Exception ex) { Label1.Visible=true; Label1.Text=ex.Message; } finally { cn.Close(); } }
------解决方案--------------------
在做Web程序之前,先要搞清楚Web程序对本地资源基本上是不可访问的.
------解决方案--------------------
public static void DownloadSmallFiles(HttpResponse _Response, string Vpath, string FielName) { _Response.Clear(); _Response.Buffer = true;