Thursday, December 6, 2012

SPDataSource

Example:
1.  <SharePoint:SPDataSource runat="server"
2.  DataSourceMode="List"
3.  SelectCommand="<View></View>"
4.  id="dataviewdatasource1" >
5.  <SelectParameters>
6.  <WebPartPages:DataFormParameter Name="ListID"
7.  ParameterKey="ListID"
8.  PropertyName="ParameterValues"
9.  DefaultValue="00000000-0000-0000-0000-000000000000" />
10. <asp:Parameter DefaultValue="{sitecollectionroot}" Name="WebUrl"></asp:Parameter>
11. </SelectParameters>
12. </SharePoint:SPDataSource>

DataSourceMode

Data Source Mode is a type of WSS data to query. The valid modes are:
  • List - Query items in a single list. Multiple rows of list data are returned. Each row represents a list item. This mode is similar to using an instance of the SPQuery class against a list. This mode can get lookup fields. This is the default mode.
  • ListOfLists - Query property values of all lists in a Web site. Multiple rows of data are returned. Each row represents a list.
  • CrossList - Query items in multiple lists in multiple Web sites in the same site collection. Multiple rows of list data are returned. Each row represents a list item. This mode is similar to using an instance of the SPSiteDataQuery class against lists in a site collection. This mode cannot get lookup fields. used for recursive query.
  • Webs - Query property values of all sub sites of a specified Web site. Multiple rows of data are returned. Each row represents a Web site.
  • ListItem - Query field values in a list item. A single row of list data is returned. The row represents a single list item.

SelectCommand

  • Select Command is an actual query for that data type.
  • Some modes don’t require a query at all.
  • In List mode, the SelectCommand roughly maps to the SPQuery object and accepts Collaborative Application Markup Language (CAML) fragments to specify things like the set of return fields, filtering, and sort order.
  • Briefly, this command will draw the wanted fields we want to draw from the data source to the DVWP. For example, if we want to draw the field “Title”, the code will be: SelectCommand="<View><ViewFields><FieldRef Name=’Title’/></ViewFields></View>"
  • But, if we want to create a query, the code will be written in CAML.SelectParameter
  • Select Parameter is each command expects a number of different parameters.
  • These parameters can refer to the parameter binding’s collection in the Data View, as well as take most ASP.Net types of parameters like Control and QueryString.

Where from? <asp:Parameter DefaultValue="…" Name="WebUrl"></asp:Parameter>

  • {sitecollectionroot} – will get the data from the root site: <asp:Parameter DefaultValue="{sitecollectionroot}" Name="WebUrl"></asp:Parameter>
  • If we want a specify sub-site: <asp:Parameter DefaultValue="/sub-site" Name="WebUrl"></asp:Parameter>

Parameteres

List and ListItem modes require the “DataFormParameter” list ID or list name, for example (CrossList for example need that parameter but not using it):
<WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="00000000-0000-0000-0000-000000000000" />
<WebPartPages:DataFormParameter Name=" ListName" ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="<List Name>" />
  • ListID – GUID that corresponds to a List’s ListID.
  • ListName – Display name for a List.
  • ListItemId – ID for a single item in ListItem mode
  • WebUrl – Url to the web. When not specified, SPDataSource uses the current web to resolve the previous parameters. You can also use this parameter to access lists in other Web sites in the same Site Collection assuming you have permissions to that list.

- Thanks to Eray Chou' post.



Tuesday, November 27, 2012

Sort & Filter on Headers


DVWP offers a tiny feature that can be very useful to the user – “Sort & Filter on Headers”. As same as the OOTB lists and libraries, which their headers offers filtering and sorting columns, it can be added to your data view by simple click:

Under Data View Tools, Design Tab - Mark the “Sort & Filter on Headers” check box:




And now you have this feature activated, displayed like this:
 

Important! This feature doesn’t support CAML Query in the DataSource tag (such as queries and CrossList mode).

Wednesday, November 21, 2012

View Last Page in DVWP XSL

In Data View Web Part, for the user, It's not very comfortable to click again and again on the "Next" button till you've rich the end. So, Add “Last” to the paging in order to move to the last page of items.


The code to insert into the "dvt_navigation" template:

<xsl:variable name="FirstItemOfLastPage">

  <xsl:choose>
    <xsl:when test="$dvt_RowCount mod $RowLimit = 0">
      <xsl:value-of select="$dvt_RowCount - ($RowLimit - 1)"></xsl:value-of>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$dvt_RowCount - ($dvt_RowCount mod $RowLimit) +1"></xsl:value-of>
    </xsl:otherwise>
  </xsl:choose>
</xsl:variable>

<a class="LastPageLink">
  <xsl:attribute name="href">javascript: <xsl:value-of select="ddwrt:GenFireServerEvent(concat('dvt_firstrow={',$FirstItemOfLastPage,'};dvt_startposition={}'))" />;</xsl:attribute>Last</a>

Sunday, November 11, 2012

Edit Form and New Form Dialog


Open a dialog model to edit current item and add new item to the list via DVWP sometimes is hard to do because of the returned values, and still, need to be modified by substring function or even more. However it can be executed by simple XSL and JS.
Define two parameters to send the as parameters to the function (considering the @FileDirRef returns 12;#/site/Lists/ListName for example):

<xsl:param name="FileURL" select="substring-after(@FileDirRef,';#')" />
<xsl:param name="FileURL2" select="concat('/',$FileURL)" />

wrap the value (title in this case) with <a> tag.

For edit:
<a href="#" onclick="javascript:openEditItemRisk({@ID},'{$FileURL2}')" ><xsl:value-of select="@Title"/></a>

For new item:
<a onclick="openNewItemRisk()">+ Create new item</a>

Attach JS file with this code:
function openNewItemRisk(){
    var options = {
    url: "../Lists/ListName/NewForm.aspx",
        allowMaximize: false,
        showClose: true,
        scroll: 0,
    dialogReturnValueCallback: silentCallbackNewForm};
    SP.UI.ModalDialog.showModalDialog(options);
}
function silentCallbackNewForm(dialogResult, returnValue) {
    location.reload();
}

function openEditItemRisk(currentId,url){
    var options = {
    url: url + "/EditForm.aspx?ID=" + currentId, //Can be changed to DispForm in order to only view the item
    allowMaximize: false,
    showClose: true,
    scroll: 0,
    dialogReturnValueCallback: silentCallbackEditForm};
    SP.UI.ModalDialog.showModalDialog(options);
}
function silentCallbackEditForm(dialogResult, returnValue) {
    location.reload();
}

Numbering Items (Descending as well) In DVWP


Having the default item ID from SharePoint can be a little bit tricky – if you erase an item, you lose the sequential order, or if you are getting the items from a number of lists you will have duplicated ID’s.
So, if the ID is not important, and you only need to number it, you can use the position (add +1 so it will start from 1 instead of 0), For example (in the rowview):

<xsl:value-of select="position()+1"/>

But, if the order should be descending you can use the number of rows and the position. For example:

In the call to rowview:
<xsl:call-template name="dvt_1.rowview">
    <xsl:with-param name="Rows" select="$Rows" />
</xsl:call-template>

In the rowview:

<xsl:template name="dvt_1.rowview">
    <xsl:param name="Rows" />
    <xsl:value-of select="count($Rows) - position() +1"/>
</xsl:template>

It will even work with paging (will preserve the number from previous page and not start over from the current page).



Wednesday, October 10, 2012

MasterPageFile Reference

On top of the page there is a line where the master page can be defined manually, or to be the default and custom master page:
<%@ Page language="C#" MasterPageFile=  ../_catalogs/masterpage/<Master Page File Name>.master meta:progid="SharePoint.WebPartPage.Document" inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" meta:webpartpageexpansion="full" %>

MasterPageFile Value
Definition
MasterPageFile="~masterurl/custom.master"

Dynamic custom master page defined in the “Site Settings -> Look and Feel -> Master Page” section.
MasterPageFile="~masterurl/default.master"

Defines the master page according to the page layout. On OOTB page layout, the master page will be v4.master for example.
MasterPageFile="../_catalogs/masterpage/Master.master"

Static specific master page definition.

Navigation Controls Values

There are some controls to navigate through in the master page, for example, logo control, site name control and more.
<SharePoint:SPLinkButton runat="server" NavigateUrl="~site/" id="onetidProjectPropertyTitleGraphic">

        <SharePoint:SiteLogoImage name="onetidHeadbnnr0" id="onetidHeadbnnr2" LogoImageUrl="/_layouts/images/siteIcon.png" runat="server"/>
    </SharePoint:SPLinkButton>

NavigateUrl Value
Result
~sitecollection/ or /
Leads to the root welcome page (site collection)
~site/
Leads to the current site welcome page.

Hope it helps,
Me.

Monday, June 18, 2012

Calendar View Links

Creating a new buttons or links to simulate the same action as switching views by the Ribbon, can be very easy to use while the Ribbon is hidden, anonymous mode, or just new UI request.

In order to do that, add this onclick function to the <a> tags or to any other tags (image, input and more) on top of the web part zone above the Calendar web part:

For Day view - onclick="javascript:MoveView('day');"
For Week view - onclick="javascript:MoveView('week');"
For Month view - onclick="javascript:MoveView('month');"

Monday, May 14, 2012

Quick Lunch Box in Results.aspx

I run into something very strange in the Results.aspx page OOTB. Suddenly a wired box appeared. It seems to be the Quick Lunch zone but without the items inside. The wired thing is in the CSS code there are styles to hide it and fix it, but they are not working properly.

The wired box on the left below the status bar:



The CSS:


The thing is that the CSS have the styles as display:none, float:left and more to hide it when you don’t have the left navigation but it seems to ignore it.
So, in the hard way, as always, add these to the CSS / to the <style> in the page so it will do the work properly:


1.  #s4-mainarea #s4-leftpanel{   
2.    display:none!important;   
3.  }   
4.  .s4-ca {   
5.      background-color: inherit;   
6.      margin-left: 0px!important;   
7. 

My Presentation from SharePoint Extreme 2012

After the big event of SharePoint 2012, here is a little web site with all of the workshop content:
Which is by the way, SharePoint Online site.

My SharePoint Extreme presentation about CQWP and XSLT editing from the event:

Have fun!

Second day - second presentation @ SharePoint Extreme 2012

Customizing Advanced Search Web Part

In the Advanced Search Web Part there are a lot of properties can be editable OOTB without designer. Some of them are for properties, the scopes, the languages, and even the fields. Moreover, the advanced search web part properties can be edit by XML.


To add properties and languages to the web part, edit them, remove and move: Edit the web part -> Properties -> Properties. In the same code there are the Properties Definitions and the Result Types. The properties definitions are the source of fields to be referenced in the Result Types, such as property name, type and display name. The Result Types are the options to search by properties according to the selected type and filtered results, for example “PowerPoint Presentations” will display results filtered by file extensions: pptx, ppt, pptm, and odp. It can be modified such as add fields, names, filters and more.



This is the XML by default:
1.  <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  
2.    <LangDefs>  
3.      <LangDef DisplayName="Arabic" LangID="ar"/>  
4.      <LangDef DisplayName="Bengali" LangID="bn"/>  
5.      <LangDef DisplayName="Bulgarian" LangID="bg"/>  
6.      <LangDef DisplayName="Catalan" LangID="ca"/>  
7.      <LangDef DisplayName="Simplified Chinese" LangID="zh-cn"/>  
8.      <LangDef DisplayName="Traditional Chinese" LangID="zh-tw"/>  
9.      <LangDef DisplayName="Croatian" LangID="hr"/>  
10.     <LangDef DisplayName="Czech" LangID="cs"/>  
11.     <LangDef DisplayName="Danish" LangID="da"/>  
12.     <LangDef DisplayName="Dutch" LangID="nl"/>  
13.     <LangDef DisplayName="English" LangID="en"/>  
14.     <LangDef DisplayName="Finnish" LangID="fi"/>  
15.     <LangDef DisplayName="French" LangID="fr"/>  
16.     <LangDef DisplayName="German" LangID="de"/>  
17.     <LangDef DisplayName="Greek" LangID="el"/>  
18.     <LangDef DisplayName="Gujarati" LangID="gu"/>  
19.     <LangDef DisplayName="Hebrew" LangID="he"/>  
20.     <LangDef DisplayName="Hindi" LangID="hi"/>  
21.     <LangDef DisplayName="Hungarian" LangID="hu"/>  
22.     <LangDef DisplayName="Icelandic" LangID="is"/>  
23.     <LangDef DisplayName="Indonesian" LangID="id"/>  
24.     <LangDef DisplayName="Italian" LangID="it"/>  
25.     <LangDef DisplayName="Japanese" LangID="ja"/>  
26.     <LangDef DisplayName="Kannada" LangID="kn"/>  
27.     <LangDef DisplayName="Korean" LangID="ko"/>  
28.     <LangDef DisplayName="Latvian" LangID="lv"/>  
29.     <LangDef DisplayName="Lithuanian" LangID="lt"/>  
30.     <LangDef DisplayName="Malay" LangID="ms"/>  
31.     <LangDef DisplayName="Malayalam" LangID="ml"/>  
32.     <LangDef DisplayName="Marathi" LangID="mr"/>  
33.     <LangDef DisplayName="Norwegian" LangID="no"/>  
34.     <LangDef DisplayName="Polish" LangID="pl"/>  
35.     <LangDef DisplayName="Portuguese" LangID="pt"/>  
36.     <LangDef DisplayName="Punjabi" LangID="pa"/>  
37.     <LangDef DisplayName="Romanian" LangID="ro"/>  
38.     <LangDef DisplayName="Russian" LangID="ru"/>  
39.     <LangDef DisplayName="Slovak" LangID="sk"/>  
40.     <LangDef DisplayName="Slovenian" LangID="sl"/>  
41.     <LangDef DisplayName="Spanish" LangID="es"/>  
42.     <LangDef DisplayName="Swedish" LangID="sv"/>  
43.     <LangDef DisplayName="Tamil" LangID="ta"/>  
44.     <LangDef DisplayName="Telugu" LangID="te"/>  
45.     <LangDef DisplayName="Thai" LangID="th"/>  
46.     <LangDef DisplayName="Turkish" LangID="tr"/>  
47.     <LangDef DisplayName="Ukrainian" LangID="uk"/>  
48.     <LangDef DisplayName="Urdu" LangID="ur"/>  
49.     <LangDef DisplayName="Vietnamese" LangID="vi"/>  
50.   </LangDefs>  
51.   <Languages>  
52.     <Language LangRef="en"/>  
53.     <Language LangRef="fr"/>  
54.     <Language LangRef="de"/>  
55.     <Language LangRef="ja"/>  
56.     <Language LangRef="zh-cn"/>  
57.     <Language LangRef="es"/>  
58.     <Language LangRef="zh-tw"/>  
59.   </Languages>  
60.   <PropertyDefs>  
61.     <PropertyDef Name="Path" DataType="text" DisplayName="URL"/>  
62.     <PropertyDef Name="Size" DataType="integer" DisplayName="Size (bytes)"/>  
63.     <PropertyDef Name="Write" DataType="datetime" DisplayName="Last Modified Date"/>  
64.     <PropertyDef Name="FileName" DataType="text" DisplayName="Name"/>  
65.     <PropertyDef Name="Description" DataType="text" DisplayName="Description"/>  
66.     <PropertyDef Name="Title" DataType="text" DisplayName="Title"/>  
67.     <PropertyDef Name="Author" DataType="text" DisplayName="Author"/>  
68.     <PropertyDef Name="DocSubject" DataType="text" DisplayName="Subject"/>  
69.     <PropertyDef Name="DocKeywords" DataType="text" DisplayName="Keywords"/>  
70.     <PropertyDef Name="DocComments" DataType="text" DisplayName="Comments"/>  
71.     <PropertyDef Name="CreatedBy" DataType="text" DisplayName="Created By"/>  
72.     <PropertyDef Name="ModifiedBy" DataType="text" DisplayName="Last Modified By"/>  
73.   </PropertyDefs>  
74.   <ResultTypes>  
75.     <ResultType DisplayName="All Results" Name="default">  
76.       <KeywordQuery/>  
77.       <PropertyRef Name="Author" />  
78.       <PropertyRef Name="Description" />  
79.       <PropertyRef Name="FileName" />  
80.       <PropertyRef Name="Size" />  
81.       <PropertyRef Name="Path" />  
82.       <PropertyRef Name="Write" />  
83.       <PropertyRef Name="CreatedBy" />  
84.       <PropertyRef Name="ModifiedBy" />  
85.     </ResultType>  
86.     <ResultType DisplayName="Documents" Name="documents">  
87.       <KeywordQuery>IsDocument="True"</KeywordQuery>  
88.       <PropertyRef Name="Author" />  
89.       <PropertyRef Name="DocComments"/>  
90.       <PropertyRef Name="Description" />  
91.       <PropertyRef Name="DocKeywords"/>  
92.       <PropertyRef Name="FileName" />  
93.       <PropertyRef Name="Size" />  
94.       <PropertyRef Name="DocSubject"/>  
95.       <PropertyRef Name="Path" />  
96.       <PropertyRef Name="Write" />  
97.       <PropertyRef Name="CreatedBy" />  
98.       <PropertyRef Name="ModifiedBy" />  
99.       <PropertyRef Name="Title"/>  
100.              </ResultType>  
101.              <ResultType DisplayName="Word Documents" Name="worddocuments">  
102.                <KeywordQuery>FileExtension="doc" OR FileExtension="docx" OR FileExtension="dot" OR FileExtension="docm" OR FileExtension="odt"</KeywordQuery>  
103.                <PropertyRef Name="Author" />  
104.                <PropertyRef Name="DocComments"/>  
105.                <PropertyRef Name="Description" />  
106.                <PropertyRef Name="DocKeywords"/>  
107.                <PropertyRef Name="FileName" />  
108.                <PropertyRef Name="Size" />  
109.                <PropertyRef Name="DocSubject"/>  
110.                <PropertyRef Name="Path" />  
111.                <PropertyRef Name="Write" />  
112.                <PropertyRef Name="CreatedBy" />  
113.                <PropertyRef Name="ModifiedBy" />  
114.                <PropertyRef Name="Title"/>  
115.              </ResultType>  
116.              <ResultType DisplayName="Excel Documents" Name="exceldocuments">  
117.                <KeywordQuery>FileExtension="xls" OR FileExtension="xlsx" OR FileExtension="xlsm" OR FileExtension="xlsb" OR FileExtension="ods"</KeywordQuery>  
118.                <PropertyRef Name="Author" />  
119.                <PropertyRef Name="DocComments"/>  
120.                <PropertyRef Name="Description" />  
121.                <PropertyRef Name="DocKeywords"/>  
122.                <PropertyRef Name="FileName" />  
123.                <PropertyRef Name="Size" />  
124.                <PropertyRef Name="DocSubject"/>  
125.                <PropertyRef Name="Path" />  
126.                <PropertyRef Name="Write" />  
127.                <PropertyRef Name="CreatedBy" />  
128.                <PropertyRef Name="ModifiedBy" />  
129.                <PropertyRef Name="Title"/>  
130.              </ResultType>  
131.              <ResultType DisplayName="PowerPoint Presentations" Name="presentations">  
132.                <KeywordQuery>FileExtension="ppt" OR FileExtension="pptx" OR FileExtension="pptm" OR FileExtension="odp"</KeywordQuery>  
133.                <PropertyRef Name="Author" />  
134.                <PropertyRef Name="DocComments"/>  
135.                <PropertyRef Name="Description" />  
136.                <PropertyRef Name="DocKeywords"/>  
137.                <PropertyRef Name="FileName" />  
138.                <PropertyRef Name="Size" />  
139.                <PropertyRef Name="DocSubject"/>  
140.                <PropertyRef Name="Path" />  
141.                <PropertyRef Name="Write" />  
142.                <PropertyRef Name="CreatedBy" />  
143.                <PropertyRef Name="ModifiedBy" />  
144.                <PropertyRef Name="Title"/>  
145.              </ResultType>  
146.            </ResultTypes>  
147.          </root>  

To remove the languages except of the English, remove the yellow marked lines.

If required, there is a possibility to change the “ResultType” and to add another one.
In order to add a new property, add the property to the “Metadata Properties”, run a crawling over the site, add it to the “PropertyDefs” and to the “ResultType” as well, and For example:

1.  <PropertyDefs>  
2.      <PropertyDef Name="{Managed Property Name}" DataType="{Type}" DisplayName="{Display Name}"/>
3.  </PropertyDefs>  

1.  <PropertyDefs>  
2.      <PropertyDef Name="ProductName" DataType="text" DisplayName="Product Name"/>
3.  </PropertyDefs>  

1.      <ResultType DisplayName="All Results" Name="default">  
2.        <KeywordQuery/>  
3.        <PropertyRef Name="ProductName" />  
4.      </ResultType>  

The fields to input the search text can be removed by the check boxes:

The scope to search in to be deifned in the “Scopes” -> “Display group”:


The result page URL for the results to be displayed:


This is the Advanced Sarch Box properties OOTB and a little bit beyond. Without any SharePoint Designer customization. There are more options to edit and customie it, but that is it for this post.