Scarpboy it babe!

February 6th, 2007 No comments

Well, let’s take a break from the SharePoint/technology in favor of a more personal/marketing post……..


Assaf Koren , my volleyball partner and a close friend in Vancouver has come up with a great tool to enable users of Orkut to send and receive instant scraps *without* a web browser. Check out their great product here.


I am sure that the Persian community with all that brutal filtering inside the country will appreciate their innovative idea.


Happy Scrapping!!!


Categories: Uncategorized Tags:

DataList and Runtime Databinding in a Web Part

February 3rd, 2007 No comments

In order to bind data returned from database or a search query to a datalist at runtime in your web part , there are certain steps that you should take,otherwise data list won’t render its content.The most important step is setting the ItemTemplate property to a proper template:


Web Part:


protected DataList _dtList;


protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
        {
                           EnsureChildControls();


                          // Database connection and populating a datatable called prDT for example


                           this._dtList.ItemTemplate = new ProductTemplate();       
                           this._dtList.DataSource = prDT; 
                           this._dtList.DataBind();
                           this._dtList.RenderControl(writer);


                               
        }


protected override void CreateChildControls()
        {
                           this._dtList = new DataList();
                           this._dtList.RepeatDirection = RepeatDirection.Horizontal;
                           this._dtList.RepeatColumns = 2;
                          Controls.Add(this._dtList);
        }


 


ProductTemplate.cs:



  public class ProductTemplate : ITemplate
    {


        void ITemplate.InstantiateIn(Control container)
        {


                        Label itemlbl = new Label();
                        itemlbl.Width = 110;
                        itemlbl.DataBinding += new EventHandler(itemlbl_DataBinding);
                        container.Controls.Add(itemlbl);
   
        }


      void itemlbl_DataBinding(object sender, EventArgs e)
        {
                     Label lbldata = (Label)sender;
                     DataListItem container = (DataListItem)lbldata.NamingContainer;
                     lbldata.Text= Convert.ToString(DataBinder.Eval(((DataListItem)container).DataItem,”ProductName”))
        }


    }


       



Categories: Uncategorized Tags:

Toronto Code Camp (March 31st)

February 2nd, 2007 No comments

“Last year’s Toronto Code Camp was a great success with over 220 attendees, 20 speakers and over $17,000 in prizes.  This year’s event is expected to be bigger and better”.


 I will also be presenting a session on MOSS 2007.There are already some great speakers  and some great sessions planned.If you are available on March 31 2007 register now as seats are limited and come out to this event for great take-aways.


Categories: Uncategorized Tags:

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: