C#网站开发----在服务器上生成临时文件,下载到客户端,然后删除临时文件

//点击按钮,完成在服务器上生成文件,并下载到客户端的任务.

  protected void btnOutput_Click(object sender, EventArgs e)
    {
        try
        {
            fillGridView_emp(this.grd_employee, this.grd_emp_temp);

            string strYear = this.lstYear.Text;
            string strSeason = this.lstPeriod.Text;

            foreach (GridViewRow grdRow in this.grd_employee.Rows)
            {


                //本想做成一次下载多个选中的对象,但是后来却发现做不了,于是就改成了CheckBox只能选中一个.这样就不会出问题了.    

                if(((CheckBox)(grdRow.Cells[4]).FindControl("ckb_Output")).Checked == true)
                {
                    string strLocalEmpNo = ((LinkButton)(grdRow.Cells[1].Controls[0])).Text.ToString();
                    string strLocalEmpName =  (grdRow.Cells[2]).Text.ToString();

                    //write to excel
                    if (false == writeToExcel(strYear, strSeason, strLocalEmpNo, strLocalEmpName))
                    {
                        //error message
                    }
                    else
                    {
                        //System.GC.Collect();放在这个地方,服务器上的EXCEL进程杀不了,

                   //若放在下面(蓝色部分)则可以,具体原因不明,有待研究.
                        string strFileName = Session["fullName"].ToString();
                        FileDownload(strFileName);
                    }
                    break;
                }
            }

        }
        catch (System.Exception ex)
        {
            ExceptionHandler.HandleException(ex);
        }
        finally
        {
            System.GC.Collect();
        }

    }



    /// <summary>
    /// 在服务器上生成一个包含所需内容的临时文件
    /// </summary>
    /// <param name="strYear"></param>
    /// <param name="strSeason"></param>
    /// <param name="strEmpNo"></param>
    /// <param name="strEmpName"></param>
    /// <returns></returns>
    [DllImport("User32.dll", CharSet = CharSet.Auto)]
    public static extern int GetWindowThreadProcessId(IntPtr hwnd,out int ID);
    public Boolean writ

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值