Search code examples
sharepointsharepoint-2010web-parts

Setting the DisplayFormURL of a CalendarView item, SPCalendarView control


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.

Problem:

I need to be able to see 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?


Solution

  • if I'm understanding you correctly you'll want to use the SPContext class

    spcontext class

    you can use it like

    SPList oListCur = SPContext.Current.List;
    SPWeb oWeb = SPContext.Current.Web;
    SPSite oSite = SPContext.Current.Site;