How to to add a Content Query WebPart programatically and use a SPSIteDataquery?

1.7k views Asked by At

This is the current scenario.

I have a central site called: XXX.

I have many subsites called with the year name: 2012, 2011, 2010, etc.

In the central site I have a list called Beneficiaries.

In ALL year sites I have a list called Request, every one of those lists have a lookup column to the Beneficiaries list in the central site.

I need to create one webpart in the central site to show all the Requests that a Benefeciary has in all sub sites. (year sites). I wonder if the contentquery webpart will do the work because I think I will have to use spsitedataquery not use spquery.

This is the code I have so far.

/// <summary>
        /// Update dashboard beneficieries.
        /// </summary>
        /// <param name="currentUnsafeWeb"></param>
        private void UpdateDashboardBeneficiaries(SPWeb currentUnsafeWeb)
        {
            Logger.LogDebug("NLSubsidiesSiteConfigSubsidyCentralEventReceiver", "UpdateDashboardBeneficiaries(SPWeb currentUnsafeWeb)", "BEGIN");

            SPFile page = null;
            try
            {
                page = currentUnsafeWeb.GetFile("beneficiaries.aspx");
                page.CheckOut();

                //Add Content Query WebPart or something else to show all request in all yearsubsites that are related to the beneficiaries list.


                page.CheckIn(string.Empty);

            }
            catch (Exception)
            {
                if (page != null) page.UndoCheckOut();
                throw;
            }

            Logger.LogDebug("NLSubsidiesSiteConfigSubsidyCentralEventReceiver", "ConfigureDashboardBeneficiaries(SPWeb currentWeb)", "END");
         }
1

There are 1 answers

0
Luis Valencia On BEST ANSWER

this post pointed me in the right direction.

http://msdn.microsoft.com/en-us/library/aa981241.aspx