How do I package a content query web part in a custom solution with its custom XSL? Do I need to store the xsl in style library's xsl style sheets folder?

I just want to have a content query web part with its custom xsl, and be able to package it in Visual Studio

2 Answers 2


You can make the customization then export the WebPart. This gives you a file with .webpart extension.

Now create a new SharePoint project in Visual Studio. Add a Visual WebPart. This creates a .webpart file. Replace this file with the one you have exported.

Now you can make the necessary changes, then package and deploy the solution.

  • And how do I connect it to XSL? Do I have to have a template in the style library xsl style sheets or can I just make an .xsl file? Also how do I deploy this template, just in a module? Do you have a walkthrough for that? Jan 27, 2015 at 16:29
  • I would suggest you directly put the xsl modification in the webpart file. That way you can avoid another file maintenance. Jan 27, 2015 at 16:30
  • But what if I have to change later the styles? Do you have a guidance for that? Jan 27, 2015 at 16:31
  • If you are changing it often the deploy the XSL file using a module. Jan 27, 2015 at 16:31
  • Thanks Amal, but do you have a guidance for these processes I can follow? Jan 27, 2015 at 18:47

Use following steps for preparation:

  1. Create the custom style sheet. Upload the style sheet Style Library.
  2. Add Content Query Web Part to a Page and then export it.
  3. Update the style related properties. Save the web part file and upload it back to SharePoint and then add it to a page and verify that your customizations are working.

Packaging in Visual Studio.

  1. Add a WebPart to the VS solution. It creates a .webpart file.
  2. Replace the contents of above .webpart file with the contents of .webpart file created during step 3 of preparation.
  3. Now add a module to the solution and replace the automatically generated .txt file with the style sheet file created in step 1 of preparation.
  4. Update the Elements.xml file of module so that style sheet is deployed to Style Library. Example
<Module Name="Styles" Url="style Library">
<File Path="Styles\newstyle.css" Url="newstyle.css" Type="GhostableInLibrary"/>

Useful references: http://www.sharepointnadeem.com/2011/09/cqwp-xsl-customizations.html http://blogs.msdn.com/b/vssharepointtoolsblog/archive/2009/11/23/how-to-deploy-a-style-sheet-into-content-library-using-visual-studio-2010-beta-2.aspx

  • Hi Nadeem, thanks for your answer, I tried packaging the CQWP by exporting it and adding it to my visual studio project, after deploying the web part on a page, it told me there are some errors in the web part, until I opened the properties and just clicked Ok again, the error is gone. No correlation ID or anything. Jan 28, 2015 at 11:20
  • hmm, not sure what can be the reason. Jan 28, 2015 at 11:27

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.