Archive

Archive for January, 2007

View of a List to filter list items for the current logged in user

January 29th, 2007 No comments

This has become a serious requirement in two of the projects we are dealing with, so I thought it is worth sharing with the community.


Let’s say, you have a list for which you want to display all the list items Created By the currently logged in user. There are two ways to do it:


A) Through web browser interface: List settings –> Filter –> Choose Created By field and make it equal to [Me]


B) If you want to put it in your site def, things are done a little bit differently.


First of all, the [Me] operator only works on lookup fields bound to the list “user information” and on the built-in system fields (i.e. “created by” OR “modified by”)


Secondly, at the end of the day [Me] is translated to an integer. In order to implement such a functionality you should locate the Schema.xml of the list or document library for which you wish to create this view for and follow these steps:


1) Open Schema.xml


2) Find views element


3) Either create a new view element or insert the following snippet into one of the existing views for which you want to implement the filter:


  <Query>
          <Where>
            <Eq>
              <FieldRef Name=”Author” />
              <Value Type=”Integer”>
                <UserID Type=”Integer” />
              </Value>
            </Eq>
          </Where>
   </Query>



  This will turn out to an actual T-SQL with where clause and equal operator ( is translated to “=”) at runtime.


4) Save Schema.xml


5) Restart IIS



Now you have the view with a filter on the current logged in user. In next post I will show you how to implement the same functionality using content query web part (CQWP) which is awesome for cases of this kind.



Categories: Uncategorized Tags:

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

January 29th, 2007 No 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:

Independent List Definitions in WSS 3.0

January 16th, 2007 No comments

In WSS 3.0, lists are no longer part of the site definitions and encapsulated in Features. This not only allows you to deal with a lighter ONET.XML, it gives you the ability to define a list template once and reference it multiple times across different site definitions (reusability is making a lot more sense in this version – I love it )


My colleague, Joubin, explains how easy it would be to point to a OOTB list template in your site definitions using the Feature framework and have them referenced in your default.aspx page of any provisioned sites off your site definition. http://www.sharepointblogs.com/joubin/archive/2007/01/16/17921.aspx


Even if you want to add your own custom list definition (such as Hardware assets) to the site def, you should follow the same instructions in his post. Package the list definition into a feature, Install and activate the feature on the server and get your site def just reference it.



Categories: Uncategorized Tags:

Don’t you love the real ASP.Net exception page?

January 16th, 2007 No comments

Tired of seeing custom/friendly exception descriptions (such as “An unexpeted error has occured”) in your sharepoint sites specially when you are developing master pages or web parts? why not trying this:


1) Locate the web.config of your site.


2) Find <SafeMode> element and enable the CallStack attribute by changing CallStack=”false” to CallStack=”true”. This ensures that the call stack and an exception message is shown when a system-level exception occurs. You can optionally change AllowPageLevelTrace=”false” to AllowPageLevelTrace=”true” for more monitoring features.


Warning: Setting the CallStack attribute to true enables this functionality for all local and *remote* clients. At this point there is no way to differentiate between these two scopes, so think twice about the information disclosure while setting this attribute.



3) Find <customErrors> and change it to  <customErrors mode=”Off” />or


Warning: Setting the mode attribute to “On” enables this functionality for all local and *remote* clients.”RemoteOnly” Specifies that custom errors are shown  only to the remote clients, and that ASP.NET generic errors to the local clients.RemoteOnly mode is usually combined with defaultRedirect attribute in 
production enviroment to redirect the user to a custom generic error page such as defaultRedirect=”GenericError.htm”.


<customErrors defaultRedirect=”GenericError.htm” mode=”RemoteOnly”>
 <error statusCode=”500″ redirect=”InternalError.htm”/>
</customErrors>


4) Find compilation element and change it to <compilation batch=”false” debug=”true”> to have the .Net framework produce debug binaries rather than release (retail) binaries. Make sure you turn this off when you go live in production.


5)IISRESET or “%systemroot%sytem32IISAPP.vbs /a AppPoolNameUnderwhichSiteIsRunning  /r”



Categories: Uncategorized Tags:

Toronto SharePoint User Group Demo: Resources

January 11th, 2007 No comments

1) PowerPoint Deck: http://blogs.devhorizon.com/downloads/TSUG01102007.zip


2) STSADM custom command to reverse engineer Site Columns and Content Types for creating elements file for a WSS v3 Feature : http://www.andrewconnell.com/blog/articles/MossStsadmWcmCommands.aspx


3) VS 2005 Template for features: http://blogs.devhorizon.com/downloads/WSSv3%20Feature.zip


Copy  the zip file to ……My DocumentsVisual Studio 2005TemplatesProjectTemplatesVisual C# and you are good to go. Just fire up the VS 2005 and you will see the template underneath the My Templates. As I said in the demo, there are some bugs in this template ,but still a good tool for heavy duty features deployment or when it is combined with STSADM custom command. I could not find the direct link the in Daniel’s site , and that’s why I put the tool directly in my space  – Definitely not a good tool for Demo:)


4) Plan Content Types for MOSS 2007:  http://technet2.microsoft.com/Office/en-us/library/63bb092a-00fe-45ff-a4b8-d8be998d1a3c1033.mspx?mfr=true


5) Plan Content Types for WSS 3.0:  http://technet2.microsoft.com/Office/en-us/library/267ab7e5-35f6-46c9-ba64-2c63d6a0dbc01033.mspx?mfr=true



Categories: Uncategorized Tags: