SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Any body know how to filter calendar? I tried these code

protected override void CreateChildControls()

    using (SPWeb web = SPContext.Current.Site.OpenWeb("/test"))
        SPList list = web.GetListByUrl("/Lists/TestCalendar");
        SPView view = list.Views["Calendar"];

        ListViewWebPart webPart = new ListViewWebPart();

        webPart.WebId = web.ID;
        webPart.ListId = list.ID;
        webPart.PageType = PAGETYPE.PAGE_DEFAULTVIEW;
        webPart.ViewContentTypeId = "0x";
        webPart.ListViewXml = GetViewXml(view);


private string GetViewXml(SPView view)
    if (ApplySearch)
        view.Query = "my custom query";

    return view.GetViewXml();

It works fine for any view except Calendar. I cannot understand What the difference and how can i solve this issue.

share|improve this question
What is "my custom query", there can be a problem in CAML Query, please post it as well – Arsalan Adam Khatri Dec 17 '12 at 15:31
@ArsalanAdamKhatri, This query is not complex and it works correctly. I'm sure because I tested this query on all items view of my calendar list. – Alexander Dec 17 '12 at 16:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.