I have a WebPart that makes use of the SPCalendarView control and in it I add items (events) dynamically from different Calendar lists from multiple sites.

like this (please note that I use a bunch of variables I haven't included here):

                    new SPCalendarItem()

                        ItemID = item["ID"].ToString(),
                        StartDate = StartTime,
                        EndDate = EndTime,
                        hasEndDate = true,
                        Title =  item["Title"].ToString(),
                        Location = Location,
                        Description = Description,
                        IsAllDayEvent = AllDayEvent,
                        IsRecurrence = Recurrance,
                        //DisplayFormUrl = ??????????,

                        CalendarType = Convert.ToInt32(SPCalendarType.Gregorian)


I need to be able to se the DisplayFormUrl dynamically as well:

Currently setting :

DisplayFormUrl =  string.Format("/Lists/{0}/DispForm.aspx", LstName)

will use the WebPart's website URL instead of the actual list's url. What I want to be able to do is:

DisplayFormUrl =  string.Format("{0}/Lists/{1}/DispForm.aspx", SiteURL,LstName)

Any ideas on how I can achieve this? (if I can)

When I compile it DisplayFormUrl automatically adds the parent web (that the webpart is in) to the URL is there anyway I can change that?

Someone please help...

I want to be able to display items with working links for multiple site like be able to use the urls:


If I can make the DisplayFormURL absolute OR Add a link for that particular event, that would be absolutely lovely.


On a general note, setting the DisplayForm URL for each item makes no sense to me. It's not that SharePoint can't give you the absolute URL, it's that you have the wrong problem :-)

Rather than setting the DisplayForm URL for each item, consider setting it for the content type instead, or even the list if you want all items to share that display form, regardless of content type.

To get the URLs that you need, check out SPWeb.ServerRelativeURL or SPWeb.URL like this:

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

Keep in mind, however, that any form is usually made up of two forms, the list form and the content type form. The list form may contain the URL while the content type contains only the template to be used. If you specify the display form URL for a content type, this will override the list form component, which may not be what you want.

Most likely, what you want to do is retrieve the SPList.DefaultDisplayFormUrl for the list in which you want to add your calendar events. Combine this with the SPWeb.Url to get the full URL:

SPList calendarList = web.Lists["Calendar"];
string displayFormURL = web.Url + calendarList.DefaultDisplayFormUrl;

Append the id of the item you want to view as a querystring parameter (ID=[itemID]) and you should be good to go.


| improve this answer | |
  • @Furuknap Thank you for the response. I ended up using a .NET Calendar because it gives me more flexibility. The problem was, I was not adding events to a list. I was retrieving events from multiple lists (from different sites) and displaying them as one using the SPCalendarView control. (Now doing the same thing with .NET) I just get the DefaultViewUrl from the site the item is from & open a popup window (JavaScript) with the appropriate url (absolute) – MyName Apr 10 '12 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.