Exporting events to google calendar Link HtmlHelper

Following is a ASP.NET MVC HtmlHelper to generate an anchor link for exporting an event to Google Calendar.
public static MvcHtmlString ExportEventToGoogleLink(this HtmlHelper htmlHelper, string title, DateTime startDateTime, DateTime endDateTime, string description, string location, string linkText, IDictionary<string, object> htmlAttributes = null)
const string dateFormat = "yyyyMMddTHHmmssZ";
Uri url = System.Web.HttpContext.Current.Request.Url;
StringBuilder sb = new StringBuilder();
sb.Append("&text=" + title);
sb.Append("&dates=" + startDateTime.ToUniversalTime().ToString(dateFormat));
sb.Append("&details=" + description);
sb.Append("&location=" + location);
sb.Append("&sprop=" + url.Scheme + "://" + url.Host);
sb.Append("&sprop=name:" + url.Host);

TagBuilder tagBuilder = new TagBuilder("a");
tagBuilder.MergeAttribute("href", sb.ToString());
tagBuilder.MergeAttribute("target", "_blank");
tagBuilder.InnerHtml = "<span class='event-export-google'>" + linkText + "</span>";
if (htmlAttributes != null)
tagBuilder.MergeAttributes(htmlAttributes, true);
return MvcHtmlString.Create(tagBuilder.ToString());

Demo Link


Popular posts from this blog

How to show only month and year fields in android Date-picker?

How to construct a B+ tree with example

Simple Pagination using jquery,mySql and PHP