protected void btniCalendarExport_Click(object sender, EventArgs e)
    {
        string sNextTaskID = this.hdnNextTaskID.Value;

        if (sNextTaskID == string.Empty)
        {
            PageCommon.WriteJsEnd(this, "This is no next action to be exported.", PageCommon.Js_RefreshSelf);
            return;
        }

        int iNextTaskID = Convert.ToInt32(sNextTaskID);

        string sCurrentPagePath = this.Server.MapPath("~/");
        string sFileName        = Guid.NewGuid().ToString() + ".ics";
        string sFilePath        = Path.Combine(Path.GetDirectoryName(sCurrentPagePath), sFileName);

        #region #region Call iCalendarToString() API

        LPWeb.BLL.LoanTasks x = new LPWeb.BLL.LoanTasks();
        string s = x.iCalendarToString(this.iLoanID, iNextTaskID, this.CurrUser.iUserID);

        #endregion

        try
        {
            using (StreamWriter sw = File.CreateText(sFilePath))
            {
                sw.Write(s);
            }

            FileInfo FileInfo1 = new FileInfo(sFilePath);
            this.Response.Clear();
            this.Response.ClearHeaders();
            this.Response.Buffer      = false;
            this.Response.ContentType = "application/octet-stream";
            this.Response.AppendHeader("Content-Disposition", "attachment;filename=Lock.ics");
            this.Response.AppendHeader("Content-Length", FileInfo1.Length.ToString());
            this.Response.WriteFile(sFilePath);
            this.Response.Flush();
            this.Response.End();
        }
        catch (Exception ex)
        {
            string sExMsg = string.Format("iCalendarExport, error: {0}", ex.Message);
            PageCommon.WriteJsEnd(this, sExMsg, PageCommon.Js_RefreshSelf);
        }
    }
Beispiel #2
0
    protected void btniCalendarExport_Click(object sender, EventArgs e)
    {
        int iNextTaskID = this.iTaskID;


        string sCurrentPagePath = this.Server.MapPath("~/");
        string sFileName        = Guid.NewGuid().ToString();
        string sFilePath        = Path.Combine(Path.GetDirectoryName(sCurrentPagePath), sFileName);

        #region #region Call iCalendarToString() API

        LPWeb.BLL.LoanTasks x = new LPWeb.BLL.LoanTasks();
        string s = x.iCalendarToString(this.iLoanID, iNextTaskID, this.CurrUser.iUserID);

        #endregion

        // save file
        if (File.Exists(sFilePath) == false)
        {
            // Create a file to write to.
            using (StreamWriter sw = File.CreateText(sFilePath))
            {
                sw.Write(s);
            }
        }

        FileInfo FileInfo1 = new FileInfo(sFilePath);
        this.Response.Clear();
        this.Response.ClearHeaders();
        this.Response.Buffer      = false;
        this.Response.ContentType = "application/octet-stream";
        this.Response.AppendHeader("Content-Disposition", "attachment;filename=Lock.ics");
        this.Response.AppendHeader("Content-Length", FileInfo1.Length.ToString());
        this.Response.WriteFile(sFilePath);
        this.Response.Flush();

        // 删除临时文件
        File.Delete(sFilePath);

        this.Response.End();
    }