protected List <MeetingItem> getList() { List <MeetingItem> MeetingItems = new List <MeetingItem>(); try { using (SPSite site = new SPSite(SPContext.Current.Web.Url)) { using (SPWeb web = site.OpenWeb()) { SPList list = (SPList)web.Lists["Meetings List"]; for (int i = 0; i < list.ItemCount; i++) { string title = Convert.ToString(list.Items[i]["Title"]); string desc = Convert.ToString(list.Items[i]["Description"]); string location = Convert.ToString(list.Items[i]["Locations"]); DateTime dateTime = Convert.ToDateTime(list.Items[i]["Event DateTime"]); SPAttachmentCollection attachments = list.Items[i].Attachments; MeetingItem myItem = new MeetingItem(title, desc, getLocation(location), dateTime, attachments); MeetingItems.Add(myItem); } } } } catch (Exception e) { Label lblError = new Label(); this.Controls.Add(lblError); if (e.InnerException != null) { lblError.Text = "An error has occured reading from the selected list. Please check the Navi properties. " + e.InnerException.ToString(); } } return(MeetingItems); }
protected HtmlTableRow returnRow(MeetingItem item) { HtmlTableRow tr = new HtmlTableRow(); //first cell HtmlTableCell tdfirst = new HtmlTableCell("td"); tdfirst.Attributes["class"] = "edges"; HtmlGenericControl h1datefirst = new HtmlGenericControl("h1"); h1datefirst.Attributes["class"] = "top"; h1datefirst.InnerHtml = item.dateTime.Day.ToString() + "/" + item.dateTime.Month.ToString(); HtmlGenericControl h2timefirst = new HtmlGenericControl("h2"); h2timefirst.Attributes["class"] = "center"; h2timefirst.InnerHtml = item.dateTime.ToString("hh:mm tt"); HtmlGenericControl h1yearfirst = new HtmlGenericControl("h1"); h1yearfirst.Attributes["class"] = "bottom"; h1yearfirst.InnerHtml = item.dateTime.Year.ToString(); tdfirst.Controls.Add(h1datefirst); tdfirst.Controls.Add(h2timefirst); tdfirst.Controls.Add(h1yearfirst); //second cell HtmlTableCell tdsecond = new HtmlTableCell("td"); tdsecond.Attributes["class"] = "middlecell"; tdsecond.InnerHtml = "<h1>" + item.title + "</h1>" + item.desc + "<br /><br />"; foreach (string[] attitem in item.attachments) { HtmlGenericControl linkToAtt = new HtmlGenericControl("a"); linkToAtt.Attributes["href"] = attitem[0]; linkToAtt.InnerHtml = attitem[1] + "<br />"; tdsecond.Controls.Add(linkToAtt); } //third cell HtmlTableCell tdthird = new HtmlTableCell("td"); tdthird.Attributes["class"] = "edges hoverpointer"; tdthird.Attributes["onclick"] = "displayMeetingLocation('" + item.location.link + "')"; HtmlGenericControl locationName = new HtmlGenericControl("h3"); locationName.InnerHtml = item.location.title; HtmlGenericControl locationAddress = new HtmlGenericControl("p"); locationAddress.InnerHtml = item.location.address; HtmlGenericControl locationContact = new HtmlGenericControl("p"); locationContact.InnerHtml = item.location.contact; tdthird.Controls.Add(locationName); tdthird.Controls.Add(locationAddress); tdthird.Controls.Add(locationContact); //put cells in a row tr.Controls.Add(tdfirst); tr.Controls.Add(tdsecond); tr.Controls.Add(tdthird); return(tr); }