Posts

Showing posts from 2024

ASP.net MVC Custom error json result

  //=============Custom Error Starts //private JsonResult ThrowJSONError(Exception e) //{ //    Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; //    //e.StackTrace //    // return Json(new { Message = e.Message }); //    return Json(new { Error = "Uh oh!" }); //} //public ActionResult DivideByZero() //{ //    try //    { //        throw new DivideByZeroException(); //    } //    catch (DivideByZeroException e) //    { //        return ThrowJSONError(e); //    } //} //=============Custom Error Ends

iCalendar - Create .ics file using C#

  using Ical.Net; using Ical.Net.CalendarComponents; using Ical.Net.DataTypes; using Ical.Net.Serialization; using NodaTime.TimeZones; using TimeZoneConverter; public class ICalNetHelper     {         #region REFERENCES         //Ical.Net 4.2.0         //https://blog.elmah.io/generate-calendar-in-ical-format-with-net-using-ical-net/         //https://github.com/rianjs/ical.net         //https://github.com/rianjs/ical.net/wiki/Deserialize-an-ics-file         //https://github.com/rianjs/ical.net/wiki         #endregion         public System.Net.Mail.Attachment CreateiCalendarMeetingInvite(string emailTo, string subject, string body, string dtMMddyyyyTHHmmssZ)         {             #region iCal Basic format             /*     ...

iCalendar - Create .ics file using Javascript

function WeeklyCalender(month,day,hour,startTime,endTime,reminderBeforeTime,frequency,summary,additionalAttributes) { var dayOfWeek = day; var startDate = new Date(); if(day!=-1) startDate.setDate(startDate.getDate() + (dayOfWeek + 7 - startDate.getDay()) % 7) startDate.setHours(hour,startTime,0,0); var endDate = new Date(); if(day!=-1) endDate.setDate(endDate.getDate() + (dayOfWeek + 7 - endDate.getDay()) % 7) endDate.setHours(hour,endTime,0,0); var untilDate = new Date(); if(day!=-1)  untilDate.setDate(untilDate.getDate() + (dayOfWeek + 7 - untilDate.getDay()) % 7) untilDate.setMonth(month);   var blob = new Blob(["BEGIN:VCALENDAR\nBEGIN:VEVENT\nCREATED:"+startDate.toISOString().replaceAll('-','').replaceAll(':','')+"\nDTEND;TZID="+Intl.DateTimeFormat().resolvedOptions().timeZone+":"+endDate.toISOString().replaceAll('-','').replaceAll(':','')+"\nDTSTAMP:"+startDate.toISOString().re...