Beispiel #1
0
        protected void BtnExport_Click(object sender, ImageClickEventArgs e)
        {
            //创建固定资产信息列表文件
            string exePath = System.AppDomain.CurrentDomain.BaseDirectory;
            string oPath   = exePath + @"\UserInfo.txt"; //-"+DateTime.Today+".txt";

            try
            {
                StreamWriter sw     = new StreamWriter(oPath);
                DataSet      userDs = baseOperation.GetStaffInfoDataSet("");
                if (userDs != null)
                {
                    DataTable userDt = userDs.Tables[0];
                    for (int i = 0; i < userDt.Rows.Count; i++)
                    {
                        DataRow userDr = userDt.Rows[i];
                        sw.WriteLine(userDr["StaffCaption"].ToString().Trim() + "|" + userDr["Password"].ToString());
                    }
                }
                sw.Close();

                String     fileName = "UserPasswordInfo.txt";
                FileStream fs       = null;
                fs = System.IO.File.Open(oPath, System.IO.FileMode.Open);
                byte[] btFile = new byte[fs.Length];
                fs.Read(btFile, 0, Convert.ToInt32(fs.Length));
                fs.Close();
                Response.Clear();
                Response.AddHeader("Content-disposition", "attachment; filename=" + fileName);
                Response.ContentType = "application/octet-stream";
                Response.BinaryWrite(btFile);
                Response.Flush();
                Response.Close();
            }
            catch (Exception ee) {
                Log.WriteLog("", "导出异常:" + ee.ToString());
            }
        }