通讯录从Database导出vCard格式

复制代码
代码
 1 #region ToVCF
 2     protected void btn_outvcf_Click(object sender, EventArgs e)
 3     {
 4         string code = Request["hid_code"].ToString().Trim(',');
 5         StringBuilder sb = new StringBuilder();
 6         if (!string.IsNullOrEmpty(code))
 7         {
 8             string sql = string.Format(@"select u_name,u_birthday,u_mobile,U_ZAnimal,u_tel,U_Constellation,u_blood,u_sex,u_email,
 9                                         u_linkadd,u_remark,u_company,u_job,u_companyemail,u_companymobile,u_companytel,
10                                         u_companyfax,u_companyadd,u_postalcode from Mobile_CardInfo where m_id in({0})", code);
11             DataView dv = zhan.Data.Sql.PubClass.ExecuteDataView("", sql);
12             if (dv != null)
13             {
14                 
15                 foreach (DataRow dr in dv.Table.Rows)
16                 {
17                     sb.Append(ExportVCF(dr));
18                 }                
19             }
20             Response.ContentEncoding = Encoding.Default;// GetEncoding("gb2312");
21             Response.ContentType = "text/x-vCard";
22             string rename = HttpUtility.UrlEncode("通讯录", Encoding.GetEncoding("utf-8"));
23             Response.ClearHeaders();
24             Response.AppendHeader("Content-disposition"string.Format("attachment;filename={0}.vcf", rename));
25             Response.Write(sb.ToString());
26             Response.End();
27         }
28     }
29     public string ExportVCF(DataRow dr)
30     {        
31         StringWriter stringWrite = new StringWriter();
32         stringWrite.WriteLine("BEGIN:VCARD");
33         stringWrite.WriteLine("VERSION:2.1");
34         stringWrite.WriteLine(string.Format("NAME:{0}", dr["u_name"]));//姓名
35         stringWrite.WriteLine(string.Format("N:;{0};;", dr["u_name"]));//姓名
36         stringWrite.WriteLine(string.Format("FN:{0}", dr["u_name"]));//姓名
37         stringWrite.WriteLine(string.Format("ADR;DOM;PARCEL;HOME:;;{0};;;;", dr["u_linkadd"]));//家庭住址
38         stringWrite.WriteLine(string.Format("ADR;INTL;PARCEL;WORK:;;{0};;;{1};", dr["u_companyadd"], dr["u_postalcode"]));//公司地址 公司邮编
39         stringWrite.WriteLine(string.Format("BDAY:{0}", Convert.ToDateTime(dr["u_birthday"].ToString()).ToString("yyyy-MM-dd")));//生日
40         stringWrite.WriteLine(string.Format("EMAIL;INTERNET:{0}", dr["u_companyemail"]));//商务邮箱
41         stringWrite.WriteLine(string.Format("EMAIL;PRODIGY:{0}", dr["u_email"]));//电子邮件
42         stringWrite.WriteLine(string.Format("ORG:{0}", dr["u_company"]));//公司名称
43         stringWrite.WriteLine(string.Format("TEL;HOME;VOICE:{0}", dr["u_tel"]));//常用固话
44         stringWrite.WriteLine(string.Format("TEL;WORK;CELL:{0}", dr["u_companymobile"]));//商务手机
45         stringWrite.WriteLine(string.Format("TEL;WORK;VOICE:{0}", dr["u_companytel"]));//公司固话
46         stringWrite.WriteLine(string.Format("TEL;WORK;FAX:{0}", dr["u_companyfax"]));//公司传真
47         stringWrite.WriteLine(string.Format("TEL;PREF:{0}", dr["u_mobile"]));//手机号码
48         stringWrite.WriteLine(string.Format("TITLE:{0}", dr["u_job"]));//职位
49         stringWrite.WriteLine(string.Format("性别:{0}", dr["u_sex"]));//性别
50         stringWrite.WriteLine(string.Format("血型:{0}", dr["u_blood"]));//血型
51         stringWrite.WriteLine(string.Format("生肖:{0}", dr["U_ZAnimal"]));//生肖
52         stringWrite.WriteLine(string.Format("星座:{0}", dr["U_Constellation"]));//星座
53         stringWrite.WriteLine(string.Format("NOTE:{0}", dr["u_remark"]));//备注
54         stringWrite.WriteLine("END:VCARD");
55         stringWrite.WriteLine("");
56         return stringWrite.ToString();
57     }    
58     #endregion
复制代码

 

posted @   94cool  阅读(317)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
< 2010年12月 >
28 29 30 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示