[웹파트 만들기] new project 웹파트로 생성 project 명 SPWebPart_Calendar class명 WebPart_Calendar_Class
1. using 한다. // using WebPart_Calendar; using System.Data; using System.Drawing; using System.Web.UI.WebControls; // using System.Security.Permissions; using System.ComponentModel; using System.Web;
2. 아까 만든 dll을 참조 추가한다.
//코드 프로젝트 원본 부분을 주석처리하고 약간 고쳐 놓은것이다. //다시 말하지만 이것은 완성작이 아니다.
using System; using System.Runtime.InteropServices; using System.Web.UI; using System.Web.UI.WebControls.WebParts; using System.Xml.Serialization;
using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using Microsoft.SharePoint.WebPartPages; // using WebPart_Calendar; using System.Data; using System.Drawing; using System.Web.UI.WebControls; // using System.Security.Permissions; using System.ComponentModel; using System.Web;
namespace SPWebPart_Calendar { [Guid("c1e86d1e-3c2d-4c09-8526-62c0c42f5cd0")] public class WebPart_Calendar_Class : System.Web.UI.WebControls.WebParts.WebPart { CustomCalendar cal; Label lbl;
public WebPart_Calendar_Class() //생성자0 { this.ExportMode = WebPartExportMode.All; } protected override void Render(HtmlTextWriter writer) { // TODO: add custom rendering code here. // writer.Write("Output HTML"); EnsureChildControls(); cal.RenderControl(writer); lbl.RenderControl(writer); } protected override void CreateChildControls() { cal = new CustomCalendar(); this.cal.ID = "Calendar1"; this.cal.CellPadding = 5; this.cal.CellSpacing = 2; this.cal.BorderColor = System.Drawing.Color.LightGray; this.cal.TitleStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#f2f2f2"); this.cal.TitleStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#6c6b6b"); this.cal.DayHeaderStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#818080"); this.cal.DayStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#9f9e9e"); this.cal.OtherMonthDayStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#CCCCCC"); this.cal.OtherMonthDayStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#f2f2f2"); this.Controls.Add(cal); lbl = new Label(); this.lbl.ID = "Label1"; this.lbl.Visible = false; this.lbl.EnableViewState = false; this.Controls.Add(lbl); this.cal.SelectionChanged += new EventHandler(cal_SelectionChanged); } protected void cal_SelectionChanged(object sender, EventArgs e) { //this.lbl.Text = this.cal.SelectedDate.Date.ToShortDateString(); SPSecurity.CodeToRunElevated listEvents = new SPSecurity.CodeToRunElevated(delegate() { RenderEventsByDate(this.cal.SelectedDate); }); SPSecurity.RunWithElevatedPrivileges(listEvents); //RenderEventsByDate(this.cal.SelectedDate); this.lbl.Visible = true; } public void RenderEventsByDate(DateTime selectedDate) { //Get the calendar events for that day SPSite siteCollection = SPContext.Current.Site; SPList calendarList = siteCollection.RootWeb.Lists["Team Calendar"]; // Construct a query that expands recurring events SPQuery query = new SPQuery(); query.ExpandRecurrence = true; query.CalendarDate = selectedDate; //여기또 수정 //query.Query = "EventDate FieldName'\'' />''\'' />" + selectedDate.ToString("yyyy-MM-ddTHH\\:mm\\:ssZ") + ""; query.Query = "" + selectedDate.ToString("yyyy-MM-ddTHH\\:mm\\:ssZ") + ""; // query.ViewFields = " Fields to View fromEvent List"; SPListItemCollection calendarItems = calendarList.GetItems(query); foreach (SPListItem item in calendarItems) { this.lbl.Text += item["Title"] + ": starts " + item["EventDate"].ToString() + " and ends " + item["EndDate"].ToString() + " "; } //If there are no events, display the message if (String.IsNullOrEmpty(this.lbl.Text)) this.lbl.Text = " There are no events for this date "; } } }
댓글 영역