因一些朋友的需要 我把导出的整理了下 贴上来 Code //导出private string headerStr = ""; private string bodyStr = ""; private string tailStr = ""; private string enterSprite = "\r\n"; protected void Button1_Click(object sender, EventArgs e) { ScheduleEntity[] seTest = sm.select_("61b065cb-5192-4980-a207-0cff70725075", DateTime.Parse("2000-1-1"), DateTime.Parse("2010-1-1")); int seLenth = seTest.Length; for (int i = 0; i < seLenth; i++) { //string t = System.DateTime.Now.Month.ToString(); bodyStr += "BEGIN:VEVENT" + enterSprite; bodyStr += "DTSTART:" + //"20070108T053000Z" + enterSprite; seTest[i].BeginTime.Year.ToString() + seTest[i].BeginTime.Month.ToString("d2") + seTest[i].BeginTime.Day.ToString("d2") + "T" + seTest[i].BeginTime.Hour.ToString("d2") + seTest[i].BeginTime.Minute.ToString("d2") + seTest[i].BeginTime.Second.ToString("d2") + seTest[i].BeginTime.Millisecond.ToString("d3") + "Z" + enterSprite; bodyStr += "DTEND:" + //"20070108T053000Z" + enterSprite; seTest[i].EndTime.Year.ToString() + seTest[i].EndTime.Month.ToString("d2") + seTest[i].EndTime.Day.ToString("d2") + "T" + seTest[i].EndTime.Hour.ToString("d2") + seTest[i].EndTime.Minute.ToString("d2") + seTest[i].EndTime.Second.ToString("d2") + seTest[i].EndTime.Millisecond.ToString("d3") + "Z" + enterSprite; bodyStr += "DTSTAMP:" + //"20070108T053000Z" + enterSprite; seTest[i].CreateTime.Year.ToString() + seTest[i].CreateTime.Month.ToString("d2") + seTest[i].CreateTime.Day.ToString("d2") + "T" + seTest[i].CreateTime.Hour.ToString("d2") + seTest[i].CreateTime.Minute.ToString("d2") + seTest[i].CreateTime.Second.ToString("d2") + seTest[i].CreateTime.Millisecond.ToString("d3") + "Z" + enterSprite; bodyStr += "UID:"+System.Guid.NewGuid().ToString()+"-lenovo.Calendar" + enterSprite;// bodyStr += "CLASS:"+"private"+ enterSprite;// bodyStr += "CREATED:" + //"20070108T053000Z" + enterSprite; seTest[i].CreateTime.Year.ToString() + seTest[i].CreateTime.Month.ToString("d2") + seTest[i].CreateTime.Day.ToString("d2") + "T" + seTest[i].CreateTime.Hour.ToString("d2") + seTest[i].CreateTime.Minute.ToString("d2") + seTest[i].CreateTime.Second.ToString("d2") + seTest[i].CreateTime.Millisecond.ToString("d3") + "Z" + enterSprite; bodyStr += "DESCRIPTION:" + seTest[i].Brief + enterSprite;// bodyStr += "LAST-MODIFIED:" + //"20070108T053000Z" + enterSprite; seTest[i].CreateTime.Year.ToString() + seTest[i].CreateTime.Month.ToString("d2") + seTest[i].CreateTime.Day.ToString("d2") + "T" + seTest[i].CreateTime.Hour.ToString("d2") + seTest[i].CreateTime.Minute.ToString("d2") + seTest[i].CreateTime.Second.ToString("d2") + seTest[i].CreateTime.Millisecond.ToString("d3") + "Z" + enterSprite; bodyStr += "LOCATION:" + seTest[i].Place + enterSprite;// bodyStr += "SEQUENCE:" + seTest[i].ScheduleTypeID.ToString() + enterSprite;// bodyStr += "STATUS:" + seTest[i].UserName + enterSprite;// bodyStr += "SUMMARY:" + seTest[i].Summary+ enterSprite; bodyStr += "TRANSP:" + "OPAQUE" + enterSprite; bodyStr += "END:VEVENT" + enterSprite; string alarmBody = "";// Alarm foreach (RemindParamEntity al in awokeList) { //短信提醒 if ((al.NeedRemind & 0x01) == 0x01) { alarmBody += "BEGIN:VALARM" + enterSprite; alarmBody += "ACTION:" + "MOBILE" + enterSprite; alarmBody += "DESCRIPTION:This is an event reminder" + enterSprite; alarmBody += "TRIGGER:" + setAwokeTime(al.TimeType,al.TimeValue) + enterSprite; alarmBody += "END:VALARM" + enterSprite; } //邮件提醒 if ((al.NeedRemind & 0x02) == 0x02) { alarmBody += "BEGIN:VALARM" + enterSprite; alarmBody += "ACTION:" + "EMAIL" + enterSprite; alarmBody += "DESCRIPTION:This is an event reminder" + enterSprite; alarmBody += "SUMMARY:Alarm notification" + enterSprite; alarmBody += "ATTENDEE:mailto:" + Common.CommonLib.GetMemberInfo().Email + enterSprite; alarmBody += "TRIGGER:" + setAwokeTime(al.TimeType, al.TimeValue) + enterSprite; alarmBody += "END:VALARM" + enterSprite; } //PC提醒 if ((al.NeedRemind & 0x04) == 0x04) { alarmBody += "BEGIN:VALARM" + enterSprite; alarmBody += "ACTION:" + "DISPLAY" + enterSprite; alarmBody += "DESCRIPTION:This is an event reminder" + enterSprite; alarmBody += "TRIGGER:" + setAwokeTime(al.TimeType, al.TimeValue) + enterSprite; alarmBody += "END:VALARM" + enterSprite; } } //include the Alarm bodyStr += alarmBody; } headerStr = "BEGIN:VCALENDAR" + enterSprite + "PRODID:-//Lenovo Inc//Lenovo Calendar 90.6054//CN" + enterSprite + "VERSION:1.0" + enterSprite + "CALSCALE:GREGORIAN" + enterSprite + "METHOD:PUBLISH" + enterSprite + "X-WR-CALNAME:chen chen" + enterSprite + "X-WR-TIMEZONE:Asia/Shanghai" + enterSprite + "BEGIN:VTIMEZONE" + enterSprite + "TZID:Asia/Shanghai" + enterSprite + "X-LIC-LOCATION:Asia/Shanghai" + enterSprite + "BEGIN:STANDARD" + enterSprite + "TZOFFSETFROM:+0800" + enterSprite + "TZOFFSETTO:+0800" + enterSprite + "TZNAME:CST" + enterSprite + "DTSTART:19700101T000000" + enterSprite + "END:STANDARD" + enterSprite + "END:VTIMEZONE" + enterSprite; tailStr = "END:VCALENDAR"+enterSprite; Response.Clear(); Response.Buffer = false; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode("fileName") + ".ics"); Response.ContentType = "text/calendar"; this.EnableViewState = false; Response.Write(headerStr+bodyStr+tailStr); //Response.Write(sb.ToString()); Response.End(); } ---------------------------- Code //换算时间 private string setAwokeTime(short valueType,int value) { string result = ""; //TRIGGER:-P0DT0H10M0S //提醒时间(TimeType) switch (valueType) { //分钟 case 1: if (value < 60) { result = "-P0DT0H" + value.ToString() + "M0S"; } else if (value < 1440) { double aa = value / 60; result = "-P0DT" + Math.Floor(aa).ToString() + "H" + (value % 60).ToString() + "M0S"; } else { double aa = value / 1440; int leftM = value % 1440;//get this day value double muniteLeft = leftM / 60;//get the hour value result = "-P" + Math.Floor(aa).ToString() + "DT" + Math.Floor(muniteLeft).ToString() + "H" + (leftM % 60).ToString() + "M0S"; } break; //小时//1440 case 2: if (value < 24) { result = "-P0DT" + value.ToString() + "H0M0S"; } else { double aa = value / 24; result = "-P"+Math.Floor(aa).ToString()+"DT" + (value%24).ToString() + "H0M0S"; } break; //天 case 3: result = "-P" + value.ToString() + "DT0H0M0S"; break; //周 case 4: result = "-P" + (value * 7).ToString() + "DT0H0M0S"; break; } return result; } ------------ public override void VerifyRenderingInServerForm(Control control) { //base.VerifyRenderingInServerForm(control); } 转载于:https://www.cnblogs.com/zhegebucuo/archive/2009/04/22/1441283.html