Posts

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...

Loading image/spinner for Anchor tag:

<a class="bg-grey-btn" data-docnum="ABC-1201" href="javascript:void(0);" onclick="downloadAFile(this); return false;">Download Document </a> Loading image/spinner for Anchor tag: Method-1: const downloadAFile = async (e) => { try { const btnElement = $(e); const btnVal = btnElement.html(); //To add css-based spinner to the button text. //if (btnElement.html().indexOf("spinner") < 0) btnElement.html(' ' + btnVal); btnElement.data('original-html', btnVal); //...... //...... //logic for service call and response handle. //...... //...... if (btnElement) { btnElement.html(btnElement.data('original-html')); } } catch (err) { console.error("Download failed:", err); if (btnElement) { btnElement.html(btnElement.data('original-html')); } } }; Method-2: const downloadAFile = async (e) => { try { const btnElement ...

MVC FileDownload as BLOB object using javascript

  MVC FileDownload as BLOB object using javascript Controller: ---------- public class BaseController : Controller { public async Task DownloadDocument(string id) { var tuple = default(Tuple ); try { var service = new xxxxxService(); //if (Regex.IsMatch(id, "^[a-zA-Z0-9-]+$"))//if (srdDocNum.All(char.IsLetterOrDigit)) if (id.Any(char.IsLetter)) tuple = await service.GetDownloadFileByDocNum(id); //SRD--Num else tuple = await service.DownloadDocumentAsync(id); if (tuple?.Item1 != null) { var bytes = (tuple.Item1).ToArray(); return File(bytes, "application/octet-stream", tuple.Item2); } else { //return View("~/Views/Error/PageNotFound.cshtml"); return File(new byte[0], "application/octet-stream", "nofile"); //Response.StatusCode = 404; } } catch (Exception ex) { LogHelper.Error($"Base/DownloadDocument: {ex.Message.ToString()}...

Show/ Hide Image Object

Image
<input onclick="img1.style.visibility= 'visible'" value="show" type="button"> <input onclick="img1.style.visibility= 'hidden'" value="hide" type="button"> <mg src="http://www.blogger.com/1.jpg" id="img1" width="578" />

Marquee on Image

Image
welcome To My Site <marquee style="color:blue;font-size:24px;top:100;position:absolute;left:200;width:400">welcome To PHP Notes and Script Site</marquee> <img src="1.jpg" width="900" height="180">