Good morning! I am trying to customize a CQWP through Visual Studio. More precisely, what I have done so far is:

  • Add OOTB CQWP to page
  • Customize Query and Presentation fields

CQWP is being displayed correctly. What I would like now is to be able to export this, or re-create a similar WP programmatically, so it can be packaged into a WSP and deployed on different environments.

What I have tried:

  • Create a WP from scratch that inherits from ContentByQueryWebPart and programmatically set the WebUrl, ListGuid, ListName, among other properties on the CreateChildControls() method
  • Instead of editing the cs file, I then tried customizing the .webpart

On both cases, after I add the WP to the page, I see that the configuration on the toolpart is correct. However, I don't see any content on the WP.

I also tried to export the OOTB WP, but I don't see how I am able to include this on a feature and deploy.

Any help would be greatly appreciated.

EDIT Added image below: First WP has been added through VS after exporting. Second one is OOTB Web Part

First WP has been added through VS after exporting. Second one is OOTB Web Part

1 Answer 1


You can export the webpart as a .webpart file. Then

  1. Create a SharePoint Solution
  2. Add a new webpart into the solution
  3. Replace the newly created .webpart file with the exported file
  4. Delete the .cs file
  5. Now open the elements.xml file and set the required properties
  6. Package and deploy the solution
  • Thank you Amal for your quick response! I tried this up to step #5, and I don't see any content on my WP, even though the properties are correctly set on the tool part. I am not sure what properties I need to set on the elements.xml, besides the group.
    – Gonzalo
    Dec 31, 2014 at 14:11
  • @Gonzalo try editing the deployed webpart properties and check what is missing or what action will brings back the data. Then you can use that information to enhance the solution. Dec 31, 2014 at 14:13
  • Just added an image showing this. First one is the result of deployment through VS following the steps you described. The second one is the OOTB WP
    – Gonzalo
    Dec 31, 2014 at 14:13
  • thanks again for taking the time to help me with this. I tried editing the properties with no success. I even tried exporting this and comparing both .webpart files and the only difference is the type under tag <metadata>
    – Gonzalo
    Dec 31, 2014 at 14:27
  • Finally made this work! I created a Visual Web Part on the first place. I tried using a Web Part instead, and it works as expected. Thank you!
    – Gonzalo
    Dec 31, 2014 at 15:28

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.