I am looking to create an "image slider" web part for my SharePoint 2010 site home page to display a nice glossy roll-up of our recent news articles. There are literally hundreds of jQuery plugins that will take any list of images display them in a very cool slider / rotator / accordian / carrousel for you -- so all I need to do is build a SharePoint web part which can be configured to point to a particular picture or assets library, load the media files from it, and then tell the jQuery plugin do it's thang.

Given that I am working in a sandboxed solution, what is my best approach for creating this web part?

My first instinct was to create a custom web part which inherits from the Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart class, as this would allow me to use the in-built methods of the CQWP to select all items of a particular content type and then present them in the jQuery plugin's expected format using some XSLT. Easy! The only problem howver, is that the ContentByQueryWebPart isn't available in the sandbox, and nor are the DataFormWebPart or XsltListViewWebPart classes.

I know I can create a completely custom web part, but it seems like that should be a last resort. What can I leverage out-of-the-box programmatically to make this all a little easier?

FYI: For those that are interested, this is the jQuery plugin that I am using: http://www.evoslider.com/examples.html

2 Answers 2


Its true that you cannot access the CQWP through code in Sandbox solutions. However, you can provision the WebPart through Elements.xml file. This way, you are utilizing the already available CQWP in SharePoint and configuring it according to your needs. Have a loot at the following code:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="Pages" Url="PageUrl" SetupPath="SiteTemplates\SPS">
    <File Path="default.aspx" Url="PageOnWhichWebPartShouldBeDisplayed.aspx" Type="GhostableInLibrary">
      <AllUsersWebPart WebPartOrder ="3" WebPartZoneID="RightColumn">
          <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
              <type name="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart, Microsoft.SharePoint.Publishing, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
              <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
                <property name="GroupBy" type="string" />
                <property name="FilterValue2" type="string" />
                <property name="BaseType" type="string" />
                <property name="AllowConnect" type="bool">True</property>
                <property name="ShowUntargetedItems" type="bool">True</property>
                <property name="DisplayName" type="string" />
                <property name="Title" type="string">My CQWP</property>
                <property name="ContentTypeName" type="string" />
                <property name="ViewFlag" type="string">0</property>
                <property name="MediaPlayerStyleSource" type="string" null="true" />
                <property name="AdditionalGroupAndSortFields" type="string" />

For all the CQWP properties, have a look here:


You can do the same with the XsltListViewWebPart too.

  • Thanks for your feedback. Unfortunately, the web part I am creating will be dropped onto the page by users (who aren't developers), so it needs to be completely hooked up to the plugin and all preconfigured. That is why I was trying to create a custom CQWP which I could then add to the gallery. Do you know of any other applicable web parts which I can access / implaement via code in a sandbox solution? This must surely be a common thing.
    – user4545
    Oct 26, 2012 at 14:02
  • In that case, you can simply place a CQWP on the page, configure it according to your needs and then export that webpart and place it in the web parts gallery. The only challenge will be the referencing of the JS and CSS files required for the slider. You can include them in the masterpage if you want or through a Content Editor Webpart. Or we might be looking at a custom webpart after all. Oct 27, 2012 at 7:29

For those playing at home, I never found a way to inherit and implement the CQWP in the sandbox. Instead, I created a custom base class which provides some basic and common functionality which is used across all our "get data from list and display it" web parts (for example, this base class is used for a custom Image Slider web part, a Media Gallery web part, an Events Calendar web part, a Corporate Announcements web part etc.)

Similar to the CQWP, my base class takes care of adding a "Datasource Settings" panel to the web part's settings pane. This allows the user to select that list / library that the web part shall retrieve its data from. Internally, it uses the SPQuery object to retrieve data from the source list and pass it back to the derived web part for processing. Plus it also takes care of all the list validation, and also deiplaying messages such as "No items to display" when the list is empty etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.