1

我创建了一个自定义日历,使用 <SharePoint:SPCalendarView id=spcalView runat="server"> </SharePoint:SPCalendarView>. 然后我在日历列表中插入了一些事件,我可以在上面创建的视图 spcalView 中显示这些事件。为此,我将SPListItemCollection(即从日历列表中检索集合)传递给了一个函数MakeSchedule()

private SPCalendarItemCollection MakeSchedule(SPListItemCollection calListItems)
        {

            SPCalendarItemCollection items = new SPCalendarItemCollection();
            for (int i = 0; i < calListItems.Count; i++)
            {
                SPListItem item = calListItems[i];
                DateTime StartTime = Convert.ToDateTime(item["EventDate"]);
                DateTime EndTime = Convert.ToDateTime(item["EndDate"]);
                string appointmentId = "";
                if (item["AppointmentID"] != null)
                    appointmentId = item["AppointmentID"].ToString();
                string clientID = "";
                if (item["clientID"] != null)
                    clientID = item["clientID"].ToString();

                string Description = "";
                if (item["Description"] != null)
                    Description = item["Description"].ToString();

                string Location = "";
                if (item["Location"] != null)
                    Location = item["Location"].ToString();

                string Title = "";
                if (item["Title"] != null)
                    Title = item["Title"].ToString();

                bool Recurrance = false;
                if (item["fRecurrence"] != null)
                    Recurrance = (bool)item["fRecurrence"];

                bool AllDayEvent = false;
                if (item["fAllDayEvent"] != null)
                    AllDayEvent = (bool)item["fAllDayEvent"];

                SPWeb web = SPContext.Current.Web;
                string relativeURL = web.ServerRelativeUrl;
                string absoluteURL = web.Url;

                items.Add(
                    new SPCalendarItem()
                    {
                        ItemID = item["ID"].ToString(),
                        StartDate = StartTime,
                        EndDate = EndTime,
                        hasEndDate = true,
                        Title = Title,
                        Location = Location,
                        Description = Description,
                        IsAllDayEvent = AllDayEvent,
                        IsRecurrence = Recurrance,
                        CalendarType = (int)SPCalendarType.Gregorian,
                        BackgroundColorClassName="ApptCnfirmed",

                        DisplayFormUrl = relativeURL + "/_layouts/TestProj.Webparts/AppointmentsEdit.aspx"
                    }
                    );
            }
            return items;
        }

在这里,对于添加到 SPCalendarItemCollection 的每个事件项,我已将 DisplayFormUrl 设置为应用程序页面。因此,当我在 Spcalendar 视图中单击一个事件时,它会被重定向到应用程序页面以及作为查询字符串单击的项目的 ID。

在 Application 页面中,检索了 ID,并根据 ID,检索了 currentLstItem。但从那我无法获得我在日历列表中添加的自定义字段。

public partial class AppointmentsEdit : LayoutsPageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string ID = Page.Request.QueryString["ID"].ToString();//this Id is the unique id of the Appointment List 
        string Source=Page.Request.QueryString["Source"].ToString();
        if (ID != "" && ID != null)
        {

            SPList lstApp = SPContext.Current.Web.Lists["Appointment"];
            SPListItem currentLstItem =            lstApp.GetItemById(Convert.ToInt32(ID.ToString()));


        }
        else
        {

        }
    }
}

这是编辑日历事件的正确方法吗?因为我在 sharepoint 的日历列表中添加了自定义字段。我尝试使用设计器,但无法获取 EditForm.aspx 背后的代码。

提前致谢!!

4

0 回答 0