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("http://www.google.com/calendar/event?action=TEMPLATE");
sb.Append("&text=" + title);
sb.Append("&dates=" + startDateTime.ToUniversalTime().ToString(dateFormat));
sb.Append("/");
sb.Append(endDateTime.ToUniversalTime().ToString(dateFormat));
sb.Append("&details=" + description);
sb.Append("&location=" + location);
sb.Append("&trp=false");
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());
}
↧
Exporting events to google calendar Link HtmlHelper
↧