Question

Background:

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):

items.Add(
                    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)
                    }
                    );

Problem:

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:

http://site1/lists/...
http://site2/lists/...

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

Était-ce utile?

La solution

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.

.b

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top