SharePoint 自定义日历






4.40/5 (4投票s)
根据自定义 SharePoint 列表显示个性化节假日/公告

引言
最近我的公司决定在员工门户上托管一个标准日历来显示节假日,但条件是日历应该显示人力资源部门希望员工了解的节假日/信息/更新,他们不想使用公告 Web 部件。
问题
我们希望在 SharePoint 内网中显示一个传统的日历作为 Web 部件,并具有以工具提示形式为每一天显示自定义信息的特性。这些自定义信息是从带有英文和中文文本的 SharePoint 自定义列表中显示的。
先决条件
此 Web 部件基于一个自定义 SharePoint 列表,并为其预定义了列才能正常工作。因此,在 SharePoint 中创建一个具有以下站点列的自定义列表
显示名称 | 内部名称 | 类型 | 目的 |
标题 | 标题 | 单行文本 | 用英文显示节假日/公告 |
节假日日期 | Holiday_x0020_Date | 日期时间(仅日期) | 要渲染的日期。 |
TitleInChinese | TitleInChinese | 单行文本 | 用中文显示节假日/公告 |
Location | Location | 单行文本 | 地点(在我的例子中是香港、澳门、中国) |
日历
此 Web 部件基于标准的 System.Web.UI.WebControls.Calendar
控件,因此该控件没有什么特别之处。但是,为了渲染带有列表的日期,我们必须重写 OnDayRender()
事件。
public class MyCalander: System.Web.UI.WebControls.Calander
{
MyWebPart oParent;
public MyCalander(MyWebPart oCurrentParent)
{
this.oParent = oCurrentParent;
}
protected override void OnDayRender(TableCell cell, CalendarDay day)
{
try
{
// This Day is rendered as a Table Cell "<TD>"
cell.ToolTip = String.Empty;
// The oParent is the parent object with all
// the properties passed when creating instance of this class.
cell.BorderWidth = new Unit(oParent.calBorderWidth);
if (day.IsToday)
{
cell.Font.Bold = true;
cell.BackColor = Color.FromKnownColor(oParent.calTodayBackColor);
cell.ForeColor = Color.FromKnownColor(oParent.calTodayForeColor);
}
if (day.IsWeekend)
{
cell.BackColor = Color.FromKnownColor(oParent.calWeekEndBackColor);
cell.ForeColor = Color.FromKnownColor(oParent.calWeekEndForeColor);
}
if (day.IsOtherMonth)
{
cell.BackColor = Color.FromKnownColor(oParent.calRestDayBackColor);
cell.ForeColor = Color.FromKnownColor(oParent.calRestDayForeColor);
}
if (this.HolidayScheduleListName == null ||
this.HolidayScheduleListName == String.Empty)
{
return;
}
SPWeb web = SPControl.GetContextWeb(this.Context);
SPSite siteCollection = SPContext.Current.Site;
SPList calendarList =
siteCollection.RootWeb.Lists[HolidayScheduleListName];
// DEFAULT TO Holiday_x0020_Date if the user has not
// provided with a exact column name.
if (oParent.HolidayDateFilterSiteColumn == null ||
oParent.HolidayDateFilterSiteColumn == "")
oParent.HolidayDateFilterSiteColumn = "Holiday_x0020_Date";
// Now check if the column exists on the list.
if (!calendarList.Fields.ContainsField
(oParent.HolidayDateFilterSiteColumn))
{
CalendarWebPart.LogMessage
(oParent.HolidayDateFilterSiteColumn + " site column not found.");
return;
}
SPQuery query = new SPQuery();
query.ExpandRecurrence = true;
query.Query = "<Where><And><Eq><FieldRef Name='"
+oParent.HolidayDateFilterSiteColumn+"'/>
<Value Type='DateTime'>" + day.Date.ToString("yyyy-MM-dd") +
"T00:00:00Z</Value></Eq>";
query.Query += "<Eq><FieldRef Name='Location'/><Value Type='Text'>" +
oParent.strLocation + "</Value></Eq>";
query.Query += "</And></Where>";
try
{
SPListItemCollection spHolidays = calendarList.GetItems(query);
foreach (SPListItem oItem in spHolidays)
{
/*
* Check if the web language is 1033 - English.
*/
if (web.Language.ToString() == "1033") cell.ToolTip =
oItem["Title"].ToString();
else oItem["TitleInChinese"].ToString();
cell.BackColor = Color.FromKnownColor(oParent.calHolidayBackColor);
cell.ForeColor = Color.FromKnownColor(oParent.calHolidayForeColor);
}
}
catch (Exception innerException)
{
// I am not throwing an error here as this is an
// exception on List; don't want to spoil user experience
// so I will go ahead and draw the day.
CalendarWebPart.LogMessage(innerException.Message);
}
}
catch (Exception e)
{
// Now this is a NASTY ERROR, Stop processing and scare the user....
CalendarWebPart.LogMessage(e.Message);
throw e;
}
}
列表查询
OnDayRender()
的关键部分是 SPQuery
。
// SELECT Title, TitleInChinese From HolidayList WHERE
// Holiday_x0020_Date = Date_of_DayRendered
// This converts to the SPQuery as :
<Where>
<And>
<Eq>
<FieldRef Name='Holiday_x0020_Date'/><Value Type='DateTime'>
01/01/2010T00:00:00Z</Value>
</Eq>
<Eq>
<FieldRef Name='Location'/><Value Type='Text'>Hong Kong</Value>
</Eq>
</And>
</Where>
要使用 DISTINCT
值构建下拉列表,请创建一个 DataView
并将 listitems
转换为 DataTable
。
要从列表中获取 DISTINCT
值;使用 SPListItemCollection.GetDataTable
方法并使用 System.Data.DataView.ToTable()
方法转换为 DataTable
。
SPQuery query = new SPQuery();
query.Query = "<OrderBy><FieldRef Name='Location'/></OrderBy>"
query.ViewFields = "<FieldRef Name='Location' />";
// SPListItemCollection.GetDataTable() converts
DataTable tblUnique = new DataView
(calendarList.GetItems(query).GetDataTable()).ToTable(true, "Location");
//Now tblUnique contains all the Unique Values from the SharePoint Custom Lists.
Web 部件参数:颜色
主要问题是整个 Web 部件的外观和感觉,因为它必须与当前主题融合。因此,简单的方法是向 Web 管理员提供一个 String
对象,他可以在其中输入 #ffffff
颜色代码,或者提供一个包含颜色名称的下拉列表。
此解决方案是使用 System.Drawing.KnownColor enum
并使用 Color.FromKnownColor()
将 KnownColor
转换为 Color
。
#region Calendar.Title.BackColor
private KnownColor TitleBackColor = KnownColor.Black;
/// <summary>
/// Title Back Color
/// </summary>
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Title Back Color"),
WebDescription("Enter a color value"),
Category("Look & Feel"),
FriendlyName("Title Back Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calTitleBackColor
{
get { return TitleBackColor; }
set { TitleBackColor = value; }
}
#endregion
下拉列表的回调
痛点是从客户端生成 OnSelectionChanged()
触发器,以便可以刷新 Web 部件。最简单的方法是在客户端编写一个 Java 函数来使用 SelectedItemText:
进行回调。
protected override void OnPreRender(EventArgs e)
{
try
{
base.OnPreRender(e);
/*
* I need to spit out client side code to get an
* injection for change in dropdown values.
*/
if (!Page.ClientScript.IsClientScriptBlockRegistered("OnChangeDD"))
{
String script = @"function dl_onchange() {
var dl=document.getElementById('" + ddlLocation.ClientID + @"');
var url = document.URL;
if (url.indexOf('?') > 0) url = url.substr(0, url.indexOf('?'));
document.location= url + '?Location='+dl.value;}";
Page.ClientScript.RegisterClientScriptBlock(typeof(Page),
"OnChangeDD", script, true);
}
if (HttpContext.Current.Request.QueryString.Count > 0)
{
this.strLocation = HttpContext.Current.Request.QueryString
["Location"];
}
// Now that I am about to vomit the HTML
// (yup after all its HTML) - Load the DropDown with values.
this.getListItems();
cal.RefreshControl(this); // Same do it for the calendar.
}
catch (Exception ex)
{
// This is a Static Method to log errors in Event Viewer
CalendarWebPart.LogMessage(ex.Message);
throw ex;
}
整合
这个 WebPart
总共有三个类
System.Web.UI.WebControls.WebParts.WebPart
,System.Web.UI.WebControls.DropDownList
System.Web.UI.WebControls.Calendar
public class CalendarWebPart : System.Web.UI.WebControls.WebParts.WebPart
{
public String strLocation = String.Empty;
# region -- Source Filter Parameters
#region Holiday Schedule List Name e.g. Holiday Schedule
/// <summary>
/// Holds the name of the list in SharePoint where the holidays are stored.
/// </summary>
private string strHolidayScheduleListName = String.Empty;
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("List Name: e.g. Holiday Schedule"),
WebDescription("Please input the holiday schedule list name.
(e.g. Holiday Schedule)"),
Category("Source"),
FriendlyName("List Name")]
public string HolidayScheduleListName
{
get { return strHolidayScheduleListName; }
set { strHolidayScheduleListName = value; }
}
#endregion
#region Holiday Lists Field Name e.g. Holiday_x0020_Date
private string strHolidayDateFilterSiteColumn = "Holiday_x0020_Date";
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Name of the Date Filter Site Column.
e.g. Holiday_x0020_Date."),
WebDescription("Exact site column name."),
Category("Source"),
FriendlyName("Date Column Name")]
public string HolidayDateFilterSiteColumn
{
get { return strHolidayDateFilterSiteColumn; }
set { strHolidayDateFilterSiteColumn = value; }
}
#endregion
#endregion
#region Calendar UI
#region -- Dimensions
private int TableHeight = 100;
/// <summary>
/// Total Height of the Calendar Control.
/// </summary>
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Calendar Height"),
WebDescription("Enter a value"),
Category("Look & Feel"),
FriendlyName("Calendar Height"),
XmlElement(ElementName = "calTableHeight")]
public int calTableHeight
{
get { return TableHeight; }
set { TableHeight = value; }
}
private int TableWidth = 250;
/// <summary>
/// Total Width of the Calendar Control
/// </summary>
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Calendar Width"),
WebDescription("Enter a value"),
Category("Look & Feel"),
FriendlyName("Calendar Width"),
XmlElement(ElementName = "calTableWeidth")]
public int calTableWidth
{
get { return TableWidth; }
set { TableWidth = value; }
}
private int CellPadding = 5;
/// <summary>
/// Calendar Cell Padding
/// </summary>
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Cell Padding"),
WebDescription("Enter a value"),
Category("Look & Feel"),
FriendlyName("Cell Padding"),
XmlElement(ElementName = "calCellPadding")]
public int calCellPadding
{
get { return CellPadding; }
set { CellPadding = value; }
}
private int CellSpacing = 2;
/// <summary>
/// Calendar Cell Space
/// </summary>
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Cell Spacing"),
WebDescription("Enter a value"),
Category("Look & Feel"),
FriendlyName("Cell Spacing"),
XmlElement(ElementName = "calCellSpacing")]
public int calCellSpacing
{
get { return CellSpacing; }
set { CellSpacing = value; }
}
#endregion
#region Calendar.BorderColor
private KnownColor BorderColor = KnownColor.White;
/// <summary>
/// Border Color
/// </summary>
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Border Color"),
WebDescription("Enter a Color value"),
Category("Look & Feel"),
FriendlyName("Border Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calBorderColor
{
get { return BorderColor; }
set { BorderColor = value; }
}
#endregion
#region Calendar.BorderWidth
private int intBorderWidth = 1;
/// <summary>
/// Border Width
/// </summary>
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Border Width"),
WebDescription("Enter the border width in unit"),
Category("Look & Feel"),
FriendlyName("Border Width"),
XmlElement(ElementName="calBorderWidth")]
public int calBorderWidth
{
get { return intBorderWidth; }
set { intBorderWidth = value; }
}
#endregion
#region Calendar.Title.BackColor
private KnownColor TitleBackColor = KnownColor.Black;
/// <summary>
/// Title Back Color
/// </summary>
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Title Back Color"),
WebDescription("Enter a color value"),
Category("Look & Feel"),
FriendlyName("Title Back Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calTitleBackColor
{
get { return TitleBackColor; }
set { TitleBackColor = value; }
}
#endregion
#region Calendar.Title.ForeColor
private KnownColor TitleForeColor = KnownColor.White;
/// <summary>
/// Title Fore Color
/// </summary>
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Title Fore Color"),
WebDescription("Enter a color value"),
Category("Look & Feel"),
FriendlyName("Title Fore Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calTitleForeColor
{
get { return TitleForeColor; }
set { TitleForeColor = value; }
}
#endregion
#region Calendar.Title.NextPrevBackColor
private KnownColor NextPrevBackColor = KnownColor.Black;
/// <summary>
/// Title Fore Color
/// </summary>
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Next Previous Back Color"),
WebDescription("Enter a color value"),
Category("Look & Feel"),
FriendlyName("Next Previous Back Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calNextPrevBackColor
{
get { return NextPrevBackColor; }
set { NextPrevBackColor = value; }
}
#endregion
#region Calendar.Title.NextPrevForeColor
private KnownColor NextPrevForeColor = KnownColor.White;
/// <summary>
/// Title Fore Color
/// </summary>
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Next Previous Fore Color"),
WebDescription("Enter a color value"),
Category("Look & Feel"),
FriendlyName("Next Previous Fore Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calNextPrevForeColor
{
get { return NextPrevForeColor; }
set { NextPrevForeColor = value; }
}
#endregion
#region Calendar.Day.HeaderBackColor
/// <summary>
/// Header Back Color
/// </summary>
private KnownColor DayHeaderBackColor = KnownColor.White;
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Day Header Back Color"),
WebDescription("Enter a color value"),
Category("Look & Feel"),
FriendlyName("Day Header Back Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calDayHeaderBackColor
{
get { return DayHeaderBackColor; }
set { DayHeaderBackColor = value; }
}
#endregion
#region Calendar.Day.HeaderForeColor
/// <summary>
/// Header Fore Color
/// </summary>
private KnownColor DayHeaderForeColor = KnownColor.Black;
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Day Header Fore Color"),
WebDescription("Enter a color value"),
Category("Look & Feel"),
FriendlyName("Day Header Fore Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calDayHeaderForeColor
{
get { return DayHeaderForeColor; }
set { DayHeaderForeColor = value; }
}
#endregion
#region Calendar.Today.BackColor
private KnownColor TodayBackColor = KnownColor.Blue;
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Today Back Color"),
WebDescription("Enter a color value"),
Category("Look & Feel"),
FriendlyName("Today Back Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calTodayBackColor
{
get { return TodayBackColor; }
set { TodayBackColor = value; }
}
#endregion
#region Calendar.Today.ForeColor
private KnownColor TodayForeColor = KnownColor.Red;
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Today Fore Color"),
WebDescription("Enter a color value"),
Category("Look & Feel"),
FriendlyName("Today Fore Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calTodayForeColor
{
get { return TodayForeColor; }
set { TodayForeColor = value; }
}
#endregion
#region Calendar.Day.BackColor
private KnownColor DayBackColor = KnownColor.LightGray;
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Day Back Color"),
WebDescription("Enter a color value"),
Category("Look & Feel"),
FriendlyName("Day Back Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calDayBackColor
{
get { return DayBackColor; }
set { DayBackColor = value; }
}
#endregion
#region Calendar.Day.ForeColor
private KnownColor DayForeColor = KnownColor.Red;
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Day Fore Color"),
WebDescription("Enter a color value"),
Category("Look & Feel"),
FriendlyName("Day Fore Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calDayForeColor
{
get { return DayForeColor; }
set { DayForeColor = value; }
}
#endregion
#region Calendar.RestDay.BackColor
private KnownColor RestDayBackColor = KnownColor.Black;
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Other Days Back Color"),
WebDescription("Enter a color value"),
Category("Look & Feel"),
FriendlyName("Other Days Back Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calRestDayBackColor
{
get { return RestDayBackColor; }
set { RestDayBackColor = value; }
}
#endregion
#region Calendar.RestDay.ForeColor
private KnownColor RestDayForeColor = KnownColor.Black;
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Other Days Fore Color"),
WebDescription("Enter a color value"),
Category("Look & Feel"),
FriendlyName("Other Days Fore Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calRestDayForeColor
{
get { return RestDayForeColor; }
set { RestDayForeColor = value; }
}
#endregion
#region Calendar.Weekend.Backcolor
private KnownColor WeekEndBackColor = KnownColor.Black;
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Weekend Back Color"),
WebDescription("Enter a color value"),
Category("Look & Feel"),
FriendlyName("Weekend Back Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calWeekEndBackColor
{
get { return WeekEndBackColor; }
set { WeekEndBackColor = value; }
}
#endregion
#region Calendar.Weekend.Forecolor
private KnownColor WeekEndForeColor = KnownColor.White;
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Weekend Fore Color"),
WebDescription("Enter a color value"),
Category("Look & Feel"),
FriendlyName("Weekend Fore Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calWeekEndForeColor
{
get { return WeekEndForeColor; }
set { WeekEndForeColor = value; }
}
#endregion
#region Calendar.Holiday.Backcolor
private KnownColor HolidayBackColor = KnownColor.BurlyWood;
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Holiday Back Color"),
WebDescription("Enter a color value"),
Category("Look & Feel"),
FriendlyName("Holiday Back Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calHolidayBackColor
{
get { return HolidayBackColor; }
set { HolidayBackColor = value; }
}
#endregion
#region Calendar.Holiday.Forecolor
private KnownColor HolidayForeColor = KnownColor.White;
[Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Holiday Fore Color"),
WebDescription("Enter a color value"),
Category("Look & Feel"),
FriendlyName("Holiday Fore Color"),
XmlElement(typeof(System.Drawing.KnownColor))]
public KnownColor calHolidayForeColor
{
get { return HolidayForeColor; }
set { HolidayForeColor = value; }
}
#endregion
#endregion
#region -- Private Objects
private DropDownList ddlLocation;
private MyCalendar cal;
private String strHref = String.Empty;
#endregion
/// <summary>
/// Constructor.
/// <remarks>
/// Allows to export all parameters of this webpart.
/// </remarks>
/// </summary>
public CalendarWebPart()
{
this.ExportMode = WebPartExportMode.All;
}
/// <summary>
/// Process the server requests before rendering controls.
/// </summary>
/// <param name="e">Server Object</param>
protected override void OnPreRender(EventArgs e)
{
try
{
base.OnPreRender(e);
/*
* I need to spit out client side code to get an
* injection for change in dropdown values.
*/
if (!Page.ClientScript.IsClientScriptBlockRegistered("OnChangeDD"))
{
String script = @"function dl_onchange() {
var dl=document.getElementById('" + ddlLocation.ClientID + @"');
var url = document.URL;
if (url.indexOf('?') > 0) url = url.substr(0, url.indexOf('?'));
document.location= url + '?Location='+dl.value;}";
Page.ClientScript.RegisterClientScriptBlock
(typeof(Page), "OnChangeDD", script, true);
}
if (HttpContext.Current.Request.QueryString.Count > 0)
{
this.strLocation =
HttpContext.Current.Request.QueryString["Location"];
}
// Now that I am about to vomit the HTML (yup after all its HTML) -
// Load the DropDown with values.
this.getListItems();
cal.RefreshControl(this); // Same do it for the calendar.
}
catch (Exception ex)
{
CalendarWebPart.LogMessage(ex.Message);
throw ex;
}
}
/// <summary>
/// WebPart method to create objects.
/// </summary>
protected override void CreateChildControls()
{
try
{
ddlLocation = new DropDownList() ;
ddlLocation.ID = "myDropDown";
ddlLocation.Attributes.Add("onchange", "dl_onchange();");
this.Controls.Add(ddlLocation);
cal = new MyCalendar(); // Create my calender
this.cal.ID = "calCalendar1";
this.Controls.Add(cal);
}
catch (Exception e)
{
CalendarWebPart.LogMessage(e.Message);
throw e;
}
}
/// <summary>
/// RenderContests event
/// </summary>
/// <param name="writer">HtmlTextWriter</param>
protected override void RenderContents(HtmlTextWriter writer)
{
try
{
//base.RenderContents(writer);
EnsureChildControls();
ddlLocation.RenderControl(writer);
cal.RenderControl(writer);
}
catch (Exception e)
{
CalendarWebPart.LogMessage(e.Message);
throw e;
}
}
/// <summary>
/// Internal method to build the drop down from the list.
/// </summary>
private void getListItems()
{
try
{
if (this.HolidayScheduleListName == null ||
this.HolidayScheduleListName == String.Empty)
{
ddlLocation.Items.Clear();
ddlLocation.Items.Add("Configure WebPart");
return;
}
SPSite siteCollection = SPContext.Current.Site;
SPList calendarList = siteCollection.RootWeb.Lists
[HolidayScheduleListName];
SPQuery query = new SPQuery();
query.ExpandRecurrence = true;
query.Query = "<orderby><fieldref name="Location"></orderby>";
query.ViewFields = "<fieldref name="Location">";
DataTable tblUnique = new DataView
(calendarList.GetItems(query).GetDataTable()).ToTable(true, "Location");
ddlLocation.Items.Clear();
foreach (DataRow row in tblUnique.Rows)
{
ddlLocation.Items.Add(row[0].ToString());
}
if (ddlLocation.Items.Count > 0)
{
if ((this.strLocation == null) ||
(this.strLocation == "")) this.strLocation =
ddlLocation.Items[0].Text;
else ddlLocation.Items.FindByValue(this.strLocation).Selected = true;
}
tblUnique = null;
}
catch (Exception ex)
{
CalendarWebPart.LogMessage(ex.Message);
throw ex;
}
}
/// <summary>
/// Write Events in custom error logs.
/// </summary>
/// <param name="errormsg"></param>
public static void LogMessage(String errormsg)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
if (!EventLog.SourceExists("calCalendar"))
{
EventLog.CreateEventSource("calCalendar", "Application");
}
EventLog.WriteEntry("calCalendar", errormsg, EventLogEntryType.Error);
});
}
}
就这样了,一个简单的 Web 部件,用于从 SharePoint 自定义列表的“标题”列显示工具提示文本。
历史
- 2010 年 9 月 17 日:初始发布