protected void btnvCardExport_Click(object sender, EventArgs e)
    {
        // 加载BorrowerInfo
        DataTable BorrowerInfo = this.GetBorrowerInfo(this.iLoanID);

        if (BorrowerInfo.Rows.Count == 0)
        {
            PageCommon.WriteJsEnd(this, "There is no borrower for this lead.", PageCommon.Js_RefreshSelf);
        }
        int iContactID = Convert.ToInt32(BorrowerInfo.Rows[0]["ContactId"]);

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

        #region #region Call vCardToString(ContactId, true) API

        LPWeb.BLL.Contacts x           = new LPWeb.BLL.Contacts();
        string             sContactStr = x.vCardToString(iContactID, true);

        #endregion

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

        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=vcard.vcf");
        this.Response.AppendHeader("Content-Length", FileInfo1.Length.ToString());
        this.Response.WriteFile(sFilePath);
        this.Response.Flush();

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

        this.Response.End();
    }
예제 #2
0
    protected void btnSaveAsVCard_Click(object sender, EventArgs e)
    {
        string sCurrentPagePath = this.Server.MapPath("~/");
        string sFileName        = Guid.NewGuid().ToString();
        string sFilePath        = Path.Combine(Path.GetDirectoryName(sCurrentPagePath), sFileName);

        #region #region Call vCardToString(ContactId, true) API

        LPWeb.BLL.Contacts x           = new LPWeb.BLL.Contacts();
        string             sContactStr = x.vCardToString(this.iContactID, true);

        #endregion

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

        //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=vcard.vcf");
        //this.Response.AppendHeader("Content-Length", FileInfo1.Length.ToString());
        //this.Response.WriteFile(sFilePath);

        this.Response.AppendHeader("Content-Length", sContactStr.Length.ToString());
        this.Response.Write(sContactStr);
        this.Response.Flush();

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

        this.Response.End();
    }