Home > Uncategorized > Use Content Query Web Part to filter a list for the current logged in user

Use Content Query Web Part to filter a list for the current logged in user

January 29th, 2007 Leave a comment Go to comments

Couple of our projects has a great need to leverage the Content Query Web Part for exposing different content onto a series of web part pages. One of the requirements dictates that a list should be filtered for the currently logged in user (described in my previous post) and CQWP should only expose the list items “Created By” that specific user (Covered in this  post). Again, you can do this either by using Web Browser Interface or your site definition as follow:


1) On a blank WSS site, create a link list named “MyLinks”. Remember that in order to get CQWP you need to activate the publishing feature. Once you have CQWP available in the site’s web part catalog, you can expose a dynamic view of content on a page in your site.


2) I put the following snippet in ONET.XML



<Modules>
    <Module Name=”DefaultBlank” Url=”” Path=””>
      <File Url=”default.aspx” NavBarHome=”True”>
          Below Snippet goes here side by side with existing elements.
      </File>
    </Module>
  </Modules>


And here is the snippet (Attention to lines in bold)


——————————————————————————-


<AllUsersWebPart WebPartZoneID=”Left” WebPartOrder=”1″><![CDATA[<webParts><webPart xmlns=”http://schemas.microsoft.com/WebPart/v3“>
<metaData><type name=”Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart, Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” /><importErrorMessage>Cannot import this Web Part.</importErrorMessage></metaData>


<data>


<properties>
<property name=”Height” type=”string” />
<property name=”GroupStyle” type=”string”>DefaultHeader</property>
<property name=”Description” type=”string”>Use to display a dynamic view of content from your site on a web page</property>
<property name=”Direction” type=”direction”>NotSet</property><property name=”DisplayColumns” type=”int”>1</property>
<property name=”FilterField2″ type=”string” /><property name=”TitleUrl” type=”string” />
<property name=”DataSourcesString” type=”string” /><property name=”SampleData” type=”string”>&lt;dsQueryResponse&gt;&lt;Rows&gt;
&lt;Row Title=”Item 1″ LinkUrl=”http://Item1” Group=”Group Header” __begincolumn=”True” __begingroup=”True” /&gt;
&lt;Row Title=”Item 2″ LinkUrl=”http://Item2” __begincolumn=”False” __begingroup=”False” /&gt;
&lt;Row Title=”Item 3″ LinkUrl=”http://Item3” __begincolumn=”False” __begingroup=”False” /&gt;
&lt;/Rows&gt;&lt;/dsQueryResponse&gt;</property><property name=”ViewContentTypeId” type=”string” />


<property name=”XslLink” type=”string” null=”true” /><property name=”UseCopyUtil” type=”bool”>True</property>
<property name=”Title” type=”string”>Content Query Web Part</property><property name=”ContentTypeName” type=”string”>Link</property>
<property name=”ChromeState” type=”chromestate”>Normal</property><property name=”ItemStyle” type=”string”>Default</property>
<property name=”NoDefaultStyle” type=”string” /><property name=”ViewFieldsOverride” type=”string” />
<property name=”GroupByFieldType” type=”string” /><property name=”AllowZoneChange” type=”bool”>True</property>
<property name=”AllowClose” type=”bool”>True</property><property name=”FilterType3″ type=”string” />
<property name=”ListName” type=”string”>MyLinks</property><property name=”UseCache” type=”bool”>True</property>
<property name=”ParameterBindings” type=”string” /><property name=”Hidden” type=”bool”>False</property>
<property name=”AdditionalGroupAndSortFields” type=”string” null=”true” /><property name=”FeedTitle” type=”string” />
<property name=”ExportMode” type=”exportmode”>All</property><property name=”HeaderXslLink” type=”string” />
<property name=”HelpMode” type=”helpmode”>Modeless</property><property name=”DataColumnRenames” type=”string” />
<property name=”Width” type=”string” /><property name=”FeedDescription” type=”string” />
<property name=”AllowHide” type=”bool”>True</property><property name=”CatalogIconImageUrl” type=”string” />
<property name=”Default” type=”string” /><property name=”FeedEnabled” type=”bool”>False</property>
<property name=”WebsOverride” type=”string” /><property name=”AllowConnect” type=”bool”>True</property>
<property name=”HelpUrl” type=”string” /><property name=”ListGuid” type=”string”>4d33ec4e-372b-4008-adf4-1119122d3334</property>
<property name=”WebUrl” type=”string”>/</property><property name=”ItemLimit” type=”int”>15</property>
<property name=”ListsOverride” type=”string” /><property name=”SortByFieldType” type=”string”>DateTime</property>
<property name=”ShowUntargetedItems” type=”bool”>False</property><property name=”TitleIconImageUrl” type=”string” />
<property name=”ViewFlag” type=”string” /><property name=”ChromeType” type=”chrometype”>TitleOnly</property>
<property name=”FilterValue2″ type=”string” /><property name=”Filter1ChainingOperator” type=”Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterChainingOperator, Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”>And</property>
<property name=”Filter2ChainingOperator” type=”Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterChainingOperator, Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”>Or</property>
<property name=”CommonViewFields” type=”string” />
<property name=”FilterType1″ type=”string”>User</property>
<property name=”GroupBy” type=”string” />
<property name=”Xsl” type=”string”>&lt;xsl:stylesheet xmlns:x=”http://www.w3.org/2001/XMLSchema” version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” xmlns:cmswrt=”http://schemas.microsoft.com/WebPart/v3/Publishing/runtime” exclude-result-prefixes=”xsl cmswrt x” &gt; &lt;xsl:import href=”/Style Library/XSL Style Sheets/Header.xsl” /&gt; &lt;xsl:import href=”/Style Library/XSL Style Sheets/ItemStyle.xsl” /&gt; &lt;xsl:import href=”/Style Library/XSL Style Sheets/ContentQueryMain.xsl” /&gt; &lt;/xsl:stylesheet&gt;</property><property name=”MissingAssembly” type=”string”>Cannot import this Web Part.</property>
<property name=”FilterOperator1″ type=”Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterFieldQueryOperator, Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”>Eq</property>
<property name=”FilterValue3″ type=”string” />
<property name=”FilterField3″ type=”string” />
<property name=”AllowEdit” type=”bool”>True</property>
<property name=”FilterOperator2″ type=”Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterFieldQueryOperator, Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”>Eq</property>
<property name=”FilterOperator3″ type=”Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterFieldQueryOperator, Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”>Eq</property>
<property name=”QueryOverride” type=”string” /><property name=”CacheXslTimeOut” type=”int”>86400</property><property name=”MainXslLink” type=”string” />
<property name=”FireInitialRow” type=”bool”>True</property>
<property name=”SortByDirection” type=”Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+SortDirection, Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”>Desc</property>
<property name=”ItemXslLink” type=”string” /><property name=”FilterByAudience” type=”bool”>False</property><property name=”DisplayName” type=”string” />
<property name=”ServerTemplate” type=”string”>103</property><property name=”GroupByDirection” type=”Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+SortDirection, Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”>Desc</property>
<property name=”FilterValue1″ type=”string”>[Me]</property><property name=”ShowWithSampleData” type=”bool”>False</property>
<property name=”BaseType” type=”string” />
<property name=”DataFields” type=”string” />
<property name=”UseSQLDataSourcePaging” type=”bool”>True</property>
<property name=”AdditionalFilterFields” type=”string” null=”true” />
<property name=”PageSize” type=”int”>-1</property><property name=”FilterType2″ type=”string” />
<property name=”ContentTypeBeginsWithId” type=”string” /><property name=”DataSourceID” type=”string” />
<property name=”SystemViewFields” type=”string” /><property name=”AllowMinimize” type=”bool”>True</property>
<property name=”FilterField1″ type=”string”>{1df5e554-ec7e-46a6-901d-d85a3881cb18}</property>
<property name=”SortBy” type=”string”>{8c06beca-0777-48f7-91c7-6da68bc07b69}</property><property name=”CacheXslStorage” type=”bool”>True</property>
</properties>
</data></webPart></webParts>]]>


</AllUsersWebPart>


This will add the CQWP in the WebPartZoneID=”Left” of default.aspx page of the site def. This will only filter the extracted data from the list and has nothing to do at list level. In order to get the same filtering at the list level you should read my previous post here.




Categories: Uncategorized Tags:
  1. No comments yet.
You must be logged in to post a comment.