Monday 11 March 2013

SharePoint 2010: Add Colors, Borders and Fonts to Web Parts


Do you want to change all web parts in all pages, all web parts in a single page or just one web part? Each of these will require a slightly different approach.
  • All web parts in all pages?
      Add the CSS to the master page, either inline or linked to a file
  • All web parts in a single page?
      Add the CSS to the page using SharePoint Designer or a Content Editor Web Part
      (If using a CEWP, add the web part below the web parts to change, i.e. last zone, last web part)
  • Just one web part?
      Add the CSS as for a single page, but prefix all of the CSS entries with the ID of the web part to change
The example CSS below is for a single web part example. It will only impact a web part with an ID of “#MSOZoneCell_WebPartWPQ5”. To find this ID, visit the web part page, use the browser’s “View Source” option and search for your web part’s name (“Shared Documents”) and browse up to find the ID, or search for “#MSOZoneCell_WebPartWPQ” and browse down to find your web part’s name. Be aware that this ID may change if you rearrange the web parts on the page!
To use the sample CSS below for all web parts, remove all of the “#MSOZoneCell_WebPartWPQ5” references.

A Web Part

Here is a terribly abused web part :-) that has an exaggerated set of colors and fonts to make each area stand out.
image

The CSS

Notes:
  • You don’t need to use all of the CSS. Pick and choose as needed.
  • This is not a complete list of what you can change in a web part. Search the HTML source of your web part page for ideas, or do a web search to see what others are doing.
  • “#MSOZoneCell_WebPartWPQ5” is the ID of a single web part to change. This is only need when changing a single web part on a single page. Your web part will have a similar ID, but with a different number.
  • The number in the web part ID may change if the web part is moved on the page.
  • “#MSOZoneCell_WebPartWPQ5.ms…”  vs “#MSOZoneCell_WebPartWPQ5<space>.ms…”
    The space is used to indicate a parent-child relationship. With the space, CSS looks for an element with an ID of “#MSOZoneCell_WebPartWPQ5” and then looks for a child element with a class name of “ms…”. Without the space, CSS looks for single element that has both the ID and the class name.
  • Anywhere there is a background property you can also set a background image by using:
       background-image:url(' someimagepath ');
  • Colors can be set using color names (“green”) and color numbers (“#00FF00”)
  • The .ms-wpTdSpace class name is used to identify the corners or ends of the web part’s title area. If you don’t define anything for these they stay hidden. See the links at the end of this article for ideas for taking advantage of these corner areas. (How about rounded tab-like corners!)

<style type="text/css">

/* === Title bar CSS === */

/* TR - title bar for web part */
#MSOZoneCell_WebPartWPQ5 .ms-WPHeader 
{
  background-color:green;
}

/*  H3 - Text in title bar of web part */
#MSOZoneCell_WebPartWPQ5 .ms-WPTitle a    
{
  color:white;
  font-family:"Comic Sans MS";
  font-size:24pt;
}

/* TD - far left and far right (corner) cells of title bar - useful for round corner tricks */
#MSOZoneCell_WebPartWPQ5 .ms-wpTdSpace
{
  /* background-image:url(' someimagepath '); */
  width:30px !important;
  background-color:red;
}

/* web part check box */
#MSOZoneCell_WebPartWPQ5 .ms-WPHeaderCbxHidden  
{
  display:none;    
}


/* === Web part background CSS === */

/*  TD - background for all but title bar of web part */
#MSOZoneCell_WebPartWPQ5.s4-wpcell  
{
  background-color:lightgreen;
  /* border-style:dashed; */
  border-style:dashed;
  border-width:5px;
}

/* TD - paging area (i.e. 1 - 5) */
#MSOZoneCell_WebPartWPQ5 .ms-bottompaging td
{
    background-color:yellow !important;
}    

/* hide the gray line above "add new" link */    
#MSOZoneCell_WebPartWPQ5 .ms-partline
{
  display:none;
}

/* selected (clicked) web part background */    
#MSOZoneCell_WebPartWPQ5.s4-wpActive
{
  background-color:fuchsia;
  border-color:red;
    /* border-style:dotted; */
}    


/* === Column headings === */

/* color for sortable column headings */
#MSOZoneCell_WebPartWPQ5 .ms-vh-div a 
{
  color:red !important;
}
/* color for non-sortable column headings */
#MSOZoneCell_WebPartWPQ5 .ms-vh-div 
{
  color:red !important;
}


/* === List text CSS === */

/* item description text */
#MSOZoneCell_WebPartWPQ5 .ms-vb2, 
#MSOZoneCell_WebPartWPQ5 .ms-vb-user a, 
#MSOZoneCell_WebPartWPQ5 .ms-vb-title a
{
  color:yellow !important;
  font-size:12pt;
}

/*  TR - alternating (#2,#4,#6...) row of web part */
#MSOZoneCell_WebPartWPQ5 .ms-alternating  
{
  background-color:navy;
}

</style>


Want rounded corners on your web parts?

See this article from Kyle Schaeffer: http://www.endusersharepoint.com/2010/11/29/web-part-style-in-sharepoint-2010/ and this article from Becky Bertram: http://blog.beckybertram.com/Lists/Posts/Post.aspx?ID=123

SharePoint 2007: Use CSS to Add Colors, Borders and Fonts to Web Parts

The CSS in this article is similar to the CSS needed for 2010, with one annoying difference… SharePoint 2010 has a CSS class defined for all web parts, s4-wpcell, that represents the main web part area. SharePoint 2007 does not have a class defined for the entire web part table. Instead it has a unique ID for each web part. That is why in the sample CSS below you will see 

#MSOZoneCell_WebPartWPQ1 to #MSOZoneCell_WebPartWPQsomenumber . In theory you could have up to fifty web parts on a page, so I guess this could go as high as fifty.
Do you want to change all web parts in all pages, all web parts in a single page or just one web part? Each of these will require a slightly different approach.
  • All web parts in all pages?
      Add the CSS to the master page, either inline or linked to a file
  • All web parts in a single page?
      Add the CSS to the page using SharePoint Designer or a Content Editor Web Part
      (If using a CEWP, add the web part below the web parts to change, i.e. last zone, last web part)
  • Just one web part?
      Add the CSS as for a single page, but prefix all of the CSS entries with the ID of the web part to change

 

The CSS for web parts is quite complicated and may areas that can be changed.

A Web Part

Here is a terribly abused web part :-) that has an exaggerated set of colors and fonts to make each area stand out. The CSS for web parts is quite complicated and there are may areas that can be changed. The CSS below will create the example shown here. In your work you would add CSS for only the parts you want to change.
image


The CSS

As you play with the web part CSS, try one edit at a time. The order you define the CSS can impact the final result. The use of “!important” after the CSS can override existing inline styles.
Notes:
  • You don’t need to use all of the CSS. Pick and choose as needed.
  • Any area can be hidden by using:   display:none
  • This is not a complete list of what you can change in a web part. Search the HTML source of your web part page for ideas, or do a web search to see what others are doing.
  • “#MSOZoneCell_WebPartWPQ5” is the ID of a single web part to change. This is only needed when changing a single web part on a single page. Your web part will have a similar ID, but with a different number.
  • The number in the web part ID may change if the web part is moved on the page.
  • Anywhere there is a background property you can usually set a background image by using:
       background-image:url(' someimagepath ');
  • Colors can be set using color names (“green”) and color numbers (“#00FF00”)

CSS to change all of the web parts on a page

To change all pages, add this CSS to your master page. To change a single page, add this CSS to a Content Editor Web Part or edit the page with SharePoint Designer and add the CSS just before the end tag for the PlaceHolderMain <asp:Content> tag. If using a Content Editor Web Part, it should be placed as the last web part on the page. This would usually be the last web part in the last column of the bottom most web part zone.
<style type="text/css">

/* CSS for web parts */


/* === Title bar CSS === */

/* TR - title bar for web part */
.ms-WPHeader 
{
  background-color:green;
}

/*  H3 - Text in title bar of web part */
.ms-WPTitle, .ms-WPTitle a    
{
  color:white !important;
  font-family:"Comic Sans MS";
  font-size:24pt;
}



/* === Web part background CSS === */

/* TD - paging area (i.e. 1 - 5) */
.ms-bottompaging td
{
  background-color:yellow !important;
}    

/* hide or change the gray line above "add new" link */    
.ms-partline
{
  /* display:none; */
  background-color:red;
}

/* "add new" area */
.ms-addnew
{
  background-color:gray !important;
}

/* There could be up to 50 web parts on a page */
/* Use your browser's View Source feature to check your zone names */
#MSOZoneCell_WebPartWPQ1,
#MSOZoneCell_WebPartWPQ2,
#MSOZoneCell_WebPartWPQ3,
#MSOZoneCell_WebPartWPQ4,
#MSOZoneCell_WebPartWPQ5,
#MSOZoneCell_WebPartWPQ6,
#MSOZoneCell_WebPartWPQ7,
#MSOZoneCell_WebPartWPQ8,
#MSOZoneCell_WebPartWPQ9,
#MSOZoneCell_WebPartWPQ10,
#MSOZoneCell_WebPartWPQ11,
#MSOZoneCell_WebPartWPQ12,
#MSOZoneCell_WebPartWPQ13,
#MSOZoneCell_WebPartWPQ14,
#MSOZoneCell_WebPartWPQ15,
#MSOZoneCell_WebPartWPQ16,
#MSOZoneCell_WebPartWPQ17,
#MSOZoneCell_WebPartWPQ18,
#MSOZoneCell_WebPartWPQ19,
#MSOZoneCell_WebPartWPQ20
{
  background-color:lightgreen;
}



/* === Column headings === */

/* color for sortable column headings */
/* there are many "diid" IDs, and this list is not complete */
.ms-vh2 .ms-vb, .ms-vh2 .ms-vb a,
#diidSortEditor, #diidSortAuthor, 
#diidSortCheckoutUser, #diidSortAssignedTo,
#diidSortTaskGroup, #diidSortLinkFilenameNoMenu, #diidSortCustomUrl,
th.ms-vh2-nograd
{
  color:red !important;
  font-size:12pt;
}




/* === List text CSS === */

/* TD - item description text (for odd numbered rows) */
.ms-vb, 
.ms-vb2, 
.ms-vb a, 
.ms-vb2 a
{
  color:white !important;
  font-size:12pt;
}

/*  TR - background alternating (for even numbered rows) */
 .ms-alternating  
{
  background-color:navy;
}

/*  TD - text for alternating (for even numbered rows) */
.ms-alternating .ms-vb, 
.ms-alternating .ms-vb2, 
.ms-alternating .ms-vb a, 
.ms-alternating .ms-vb2 a
{
  color:red !important;
}

/* border (if enabled in the web part's properties */
.ms-WPBorder
{
  border-color:red;
  border-width:thick;
  border-style:dashed;
}



/* background and text for list web parts without column headings */
/* links list, calendar list... */
/* web parts with no items "There are currently no..." */
.ms-summarycustombody td,
.ms-summarycustombody td a
{
  background-color:yellow !important;
  color:red !important;
}


</style>

 

CSS to change a single web part

To select a single web part we will use the same CSS as above, but prefix each item with the ID of the web part. To find this ID, use your browser’s View Source feature and search for the name of your web part. Somewhere above this you will find a #MSOZoneCell_WebPartWPQsomenumber that represents your web part.
Here’s what you might find if looking for the “Airshow Pictures” web part:
image

CSS for web part #MSOZoneCell_WebPartWPQ17:
<style type="text/css">

/* CSS for web parts */


/* === Title bar CSS === */

/* TR - title bar for web part */
#MSOZoneCell_WebPartWPQ17 .ms-WPHeader 
{
  background-color:green;
}

/*  H3 - Text in title bar of web part */
#MSOZoneCell_WebPartWPQ17 .ms-WPTitle, #MSOZoneCell_WebPartWPQ17 .ms-WPTitle a    
{
  color:white !important;
  font-family:"Comic Sans MS";
  font-size:24pt;
}



/* === Web part background CSS === */

/* TD - paging area (i.e. 1 - 5) */
#MSOZoneCell_WebPartWPQ17 .ms-bottompaging td
{
  background-color:yellow !important;
}    

/* hide or change the gray line above "add new" link */    
#MSOZoneCell_WebPartWPQ17 .ms-partline
{
  /* display:none; */
  background-color:red;
}

/* "add new" area */
#MSOZoneCell_WebPartWPQ17 .ms-addnew
{
  background-color:gray !important;
}

/* There could be up to 50 web parts on a page */
/* Use your browser's View Source feature to check your zone names */
#MSOZoneCell_WebPartWPQ17
{
  background-color:lightgreen;
}



/* === Column headings === */

/* color for sortable column headings */
/* there are many "diid" IDs, and this list is not complete */
#MSOZoneCell_WebPartWPQ17 .ms-vh2 .ms-vb, #MSOZoneCell_WebPartWPQ17 .ms-vh2 .ms-vb a,
#MSOZoneCell_WebPartWPQ17 #diidSortEditor, #MSOZoneCell_WebPartWPQ17 #diidSortAuthor, 
#MSOZoneCell_WebPartWPQ17 #diidSortCheckoutUser, #MSOZoneCell_WebPartWPQ17 #diidSortAssignedTo,
#MSOZoneCell_WebPartWPQ17 #diidSortTaskGroup, #MSOZoneCell_WebPartWPQ17 #diidSortLinkFilenameNoMenu, 
#MSOZoneCell_WebPartWPQ17 #diidSortCustomUrl,
#MSOZoneCell_WebPartWPQ17 th.ms-vh2-nograd
{
  color:red !important;
  font-size:12pt;
}




/* === List text CSS === */

/* TD - item description text (for odd numbered rows) */
#MSOZoneCell_WebPartWPQ17 .ms-vb, 
#MSOZoneCell_WebPartWPQ17 .ms-vb2, 
#MSOZoneCell_WebPartWPQ17 .ms-vb a, 
#MSOZoneCell_WebPartWPQ17 .ms-vb2 a
{
  color:white !important;
  font-size:12pt;
}

/*  TR - background alternating (for even numbered rows) */
#MSOZoneCell_WebPartWPQ17 .ms-alternating  
{
  background-color:navy;
}

/*  TD - text for alternating (for even numbered rows) */
#MSOZoneCell_WebPartWPQ17 .ms-alternating .ms-vb, 
#MSOZoneCell_WebPartWPQ17 .ms-alternating .ms-vb2, 
#MSOZoneCell_WebPartWPQ17 .ms-alternating .ms-vb a, 
#MSOZoneCell_WebPartWPQ17 .ms-alternating .ms-vb2 a
{
  color:red !important;
}

/* border (if enabled in the web part's properties */
#MSOZoneCell_WebPartWPQ17 .ms-WPBorder
{
  border-color:red;
  border-width:thick;
  border-style:dashed;
}



/* background and text for list web parts without column headings */
/* links list, calendar list... */
/* web parts with no items "There are currently no..." */
#MSOZoneCell_WebPartWPQ17 .ms-summarycustombody td,
#MSOZoneCell_WebPartWPQ17 .ms-summarycustombody td a
{
  background-color:yellow !important;
  color:red !important;
}


</style>

In closing…

There’s always more you can change! Use your browser’s “View Source” feature to explorer the HTML and CSS delivered by SharePoint to see what else you can do. You can also use the add in developer tool bars for Internet Explorer and FireFox to explore the CSS. Some of the cool CSS things you may want to do will probably not work in all browsers, especially Internet Explorer 6, so test, test test.

Also take a look at the CSS reference and branding blogs on the web like these:
http://www.heathersolomon.com/content/sp07cssreference.htm
http://weblogs.asp.net/bsimser/archive/2007/04/01/css-reference-chart-for-sharepoint-2007-pdf-version.aspx

SharePoint Designer 2007 – Business Days Task Reminder Workflow

1. In this article we will discuss how to use SharePoint Designer (SPD) 2007 to create a Business Days Task Reminder Workflow. Here is our scenario:

   a. A business leader assigns a task or tasks to an employee with a due date

   b. The employee receives an initial task alert e-mail message

   c. Four business days before the due date, if the task has not been completed, the employee receives a reminder e-mail

   d. Two business days after the due date, if the task has not been completed, the employee receives the first late reminder e-mail

   e. Seven business days after the due date, if the task has not been completed, the employee receives the first second reminder e-mail

2. To setup our environment we will need to create a custom task list. From the front page of your SharePoint site follow this click path: Site Actions -> Create -> Tracking -> Tasks. Name the new list “Business Days Task Reminder Workflow”. Choose “No” for the “Send e-mail when ownership is assigned” function. The list will have the following standard fields:

  • Title - Single Line of Text
  • Priority - Choice
  • Status - Choice
  • % Complete - Number
  • Assigned To - Person or Group
  • Description - Multiple lines of text
  • Start Date - Date and Time
  • Due Date - Date and Time
3. To build this application we will need four custom components, the SPD workflow to send the e-mail alerts, and three calculated columns to define the proper business day ranges, i.e. four days before due date, two days after the due date, and seven days after the due date.

4. To build the calculated columns we need to first configure our calculated columns to count business days (Monday through Friday) and ignore weekends (Saturday and Sunday). This can be done using the calculated column’s Weekday function and some simple conditional logic. The Weekday function returns an integer for each day of the week, as shown below:

  • Sunday 1
  • Monday 2
  • Tuesday 3
  • Wednesday 4
  • Thursday 5
  • Friday 6
  • Saturday 7
Now using the Weekday function we can use some simple conditional logic to determine business day, such as shown below:

   If Weekday > 1 and Weekday < 7

5. Unfortunately it’s not enough to simply know that the date is a business day, we also have to know how many business days it is from the Due Date, and we have to know this for both before and after the due date. So let’s look at the logic to determine these dates, first here is the logic for calculating 4 business days before the Due Date:

   =IF(WEEKDAY([Due Date])<6,[Due Date]-6,IF(WEEKDAY([Due Date])=6,[Due Date]-4,[Due Date]-4))

Essentially this logic can be explained as follows:
   • If the Due Date is before Friday, subtract 6 from the Due Date to derive the date 4 business days before the Due Date
   • If the Due Date is a Friday, subtract 4 from the Due Date to derive the date 4 business days before the Due Date
   • We don’t need logic for a Due Date of Saturday or Sunday since those aren’t business days

6. Next, here is the logic for calculating 2 business days after the Due Date:

   =IF(WEEKDAY([Due Date])>4,[Due Date]+4,IF(WEEKDAY([Due Date])>1,[Due Date]+2,[Due Date]+2))

Essentially this logic can be explained as follows:

   • If the Due Date is after Wednesday, add 4 to the Due Date to derive the date 2 business days after the Due Date

   • If the Due Date is after Sunday, add 4 to the Due Date to derive the date 2 business days after the Due Date

   • We don’t need logic for a Due Date of Saturday or Sunday since those aren’t business days

7. Finally, here is the logic for calculating 7 business days after the Due Date:

   =IF(WEEKDAY([Due Date])<5,[Due Date]+9,[Due Date]+11)

Essentially this logic can be explained as follows:

   • If the Due Date is before Thursday, add 9 to the Due Date to derive the date 7 business days after the Due Date

   • If the Due Date is Thursday or later, add 11 to the Due Date to derive the date 7 business days after the Due Date

8. Next we need to add all the other lists elements as shown below (Picture1):

There is one other calculated column, Start Date – No Time, its calculation is shown below:

      =TEXT([Start Date],"mmm-dd-yyyy")

And finally, there are two choice columns, they have these values:

   • Priority:

       (1) High

       (2) Normal

       (3) Low

   • Status:

      No Action Taken

      Approved

     Denied

9. Now that we have all the date calculations and other columns in place we can easily create a workflow to send reminders on those dynamic dates. The workflow will be configured to run on "Item Created". Our workflow will have the following four steps:

   a. Send Initial Email

   b. Remind 4 Days Before

   c. Remind 2 Days After

   d. Remind 7 Days After

10. Here is the logic for Step 1 – Send Initial Email (Picture 2):

The “Due Date – No Time does not contain Dec-30-1899” and the “Start Date – No Time does not contain Dec-30-1899”. These conditions are present to prevent the workflow from running if the user has not provided a Due Date or a Start Date. Normally these would be mandatory fields but in this case the customer wanted the ability to do a draft task, and not have to worry about the workflow sending out partial data. If the user doesn’t supply a Due Date or a Start Date the calculated column will generate a date of Dec-30-1899 (because the date is blank) and the workflow will not start.

I use a Boolean called First Run to tell me if the workflow has been rerun and if so to protect against certain conditions causing errors. As you will see, all the other steps will only be run if First Run equals “No”. The First Run value is changed when the Action “Update Items in Tasks” runs (the third Action in this step).

The initial e-mail is sent to the Assignee in the second Action of this step. Obviously the content of the e-mail can be whatever the user requires but essentially it is informing the recipient about the details of the tasks they must perform.

As you can see in the pause action, the pause is set to a date and the date is set equal to the calculated column “Due Date Minus 4 BDs”.

11. Here is the logic for Step 2 - Remind 4 Days Before (Picture 3):

In the conditions the First Run value should now be changed to “No”, if the value is “Yes” it means the conditions of the first step were not met and therefore this step should not run either.

The second e-mail is sent to the Assignee in the second Action of this step. The content of the e-mail can be whatever the user requires but basically it’s a reminder that the task has still not been completed.

As you can see in the pause action, the pause is set to a date and the date is set equal to the calculated column “Due Date Plus 2 BDs”.

12. Here is the logic for Step 3 - Remind 2 Days After (Picture 4):

Again, in the conditions the First Run value should now be changed to “No”, if the value is “Yes” it means the conditions of the first step were not met and therefore this step should not run either.

The third e-mail is sent to the Assignee in the second Action of this step. The content of the e-mail can be whatever the user requires but again basically it’s a reminder that the task has still not been completed.

As you can see in the pause action, the pause is set to a date and the date is set equal to the calculated column “Due Date Plus 7 BDs”.

13. Here is the logic for Step 3 - Remind 7 Days After (Picture 5):

Again, in the conditions the First Run value should now be changed to “No”, if the value is “Yes” it means the conditions of the first step were not met and therefore this step should not run either.

The final e-mail is sent to the Assignee in the second Action of this step. The content of the e-mail can be whatever the user requires but basically it’s a notice to the end user that the task has still not been completed within the allotted time.

14. OK, now both our calculated columns and our workflow are ready! Now let’s try out our application. Create a new task in the task list. Fill out the task as normally but in the Status field choose “No Action Taken”. For testing choose yourself as the “Assigned To”. Select the current date as the “Start Date”, and a day a week from now as the “Due Date”. Finally, click the OK button to start the workflow.

15. If everything is built correctly the workflow should send out an initial e-mail, a reminder e-mail 4 business days before the Due Date, another reminder e-mail 2 business days after the Due Date, and a final reminder e-mail 7 business days after the Due Date.

16. As always the power and utility of SharePoint Designer workflows amazes me – all this function without any code – now that is awesome

SharePoint Content Query web part like a SharePoint List View

I have been working on a solution to aggregate documents from sub sites to the top level site of SharePoint with the out of the box features. To accomplish this you will have to work with the Content Query web part of SharePoint.
The Content Query web part works great but it doesn’t look like a list view and that was the styling I wanted. So let’s get working and create the styling we want.
To get the content query web part to look like a list view you have to get trough the following steps:

Step 1
Enable the “SharePoint Server Publication Infrastructure” feature if you haven’t already got the feature enabled. This feature makes sure you have the “Content Query” web part available within the web part gallery.
SharePoint-Server-Publishing-Infrastructure

Step 2
Go to the page were you would like to display the “Content Query” web part and place it on the page. The web part can be found under the “Content Rollup” category.
Edit the web part and specify the query you would like to preform. If you have specified the query save the web part and export it.
Note: if you want to query a certain type of content and this content is available within the subsites but not on the root you can not use the UI to create the query. If you want to use the UI you have to make the type available within the root site.
Webpart-Export

Step 3
You can add your custom columns to the query. This can be accomplish by editing the “CommonViewFields” property of the web part:
1
<property name="CommonViewFields" type="string">LinkFilename,Text;Title,Text;</property>
The value of the property must be in the following format [InternalName],[Type];[InternalName],[Type];

Step 4
If you would like to read out those properties by a more meaningful name you can change the “DataColumnRenames” property. This property will take care of the renaming for us.
1
<property name="DataColumnRenames" type="string">Title,Title;LinkFilename,Name</property>
The value of the property must be in the following format [InternalName],[New Name];[InternalName],[New Name];

Step 5
Now that we have defined our columns we will need to edit the xslt template to render the columns. We will have to open SharePoint Designer and open the Style Library of the site.
SharePoint-Designer
First we will edit the “ContentQueryMain.xsl” file. Within the file find the following line (79):
<xsl:template name=”OuterTemplate.Body”>
Within this template a call will be made the ItemTemplate. Within the call we will have to pass a new parameter called “LastRow” so that we know when we will have to close our grid.
For this search for the following lines (128):




<xsl:call-template name="OuterTemplate.CallItemTemplate">
    <xsl:with-param name="CurPosition" select="$CurPosition" />
</xsl:call-template>

And change it to:





<xsl:call-template name="OuterTemplate.CallItemTemplate">
    <xsl:with-param name="CurPosition" select="$CurPosition" />
    <xsl:with-param name="LastRow" select="$LastRow" />
</xsl:call-template>

Now that we pass the parameter we also have to change the template to accept the parameter.
Go to line 147 and you see the “CallItemTemplate”. Copy the second line and past it directly beneath it and make it look like this:




<xsl:template name="OuterTemplate.CallItemTemplate">
<xsl:param name="CurPosition" />
<xsl:param name="LastRow" />

Because we want to use this within our custom item template we also have give the parameter through to the template by adding a when statement just before the <xsl:otherwise> within the CallItemTemplate:






<xsl:when test="@Style='SPGrid'">
 <xsl:apply-templates select="." mode="itemstyle">
  <xsl:with-param name="CurPos" select="$CurPosition" />
  <xsl:with-param name="Last" select="$LastRow" />
 </xsl:apply-templates>
</xsl:when>
In this statement we specify that it only has to pass-through the parameter when the item template is SPGrid. So our custom template is going to be called “SPGrid”.

Step 5
Now it is  time to edit the “ItemStyle.xsl” file. Within this file we add our custom xslt item template:



























































<xsl:template name="SPGrid" match="Row[@Style='SPGrid']" mode="itemstyle">
    <xsl:param name="CurPos" />
    <xsl:param name="Last" />
 
    <xsl:variable name="SafeImageUrl">
      <xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
        <xsl:with-param name="UrlColumnName" select="'ImageUrl'"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="SafeLinkUrl">
      <xsl:call-template name="OuterTemplate.GetSafeLink">
        <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="DisplayTitle">
      <xsl:call-template name="OuterTemplate.GetTitle">
        <xsl:with-param name="Title" select="@Title"/>
        <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="LinkTarget">
      <xsl:if test="@OpenInNewWindow = 'True'" >_blank</xsl:if>
    </xsl:variable>
 
    <xsl:variable name="tableStart">
      <xsl:if test="$CurPos = 1">
       <![CDATA[
        <table width="100%" class="ms-listviewtable" cellpadding="1" cellspacing="0" border="0">
          <tr class="ms-viewheadertr ms-vhltr">
            <th class="ms-vh-icon"></th>
            <th class="ms-vh2">Name</th>
          </tr>]]>  
      </xsl:if>
    </xsl:variable>
 
    <xsl:variable name="tableEnd">
      <xsl:if test="$CurPos = $Last">
        <![CDATA[ </table> ]]>
      </xsl:if>
    </xsl:variable>
 
    <xsl:value-of select="$tableStart" disable-output-escaping="yes"/>
    <tr class="ms-alternating ms-itmhover">
      <td class="ms-vb-icon">
          <xsl:if test="string-length(@DocumentIconImageUrl) != 0">
            <div class="image-area-left">
              <img class="image" src="{@DocumentIconImageUrl}" title="" />
            </div>
        </xsl:if>
      </td>
      <td class="ms-vb2">
        <a href="{$SafeLinkUrl}" title="{@LinkToolTip}">                  <xsl:value-of select="$DisplayTitle"/>
        </a>
      </td>
      <td>
        <xsl:value-of select="@Title"/>
      </td>
    </tr>
    <xsl:value-of select="$tableEnd" disable-output-escaping="yes"/>
  </xsl:template>
The displayed xslt has to be placed just above the closing </xsl:stylesheet> tag. This xsl creates a template for each item and will display the icon , the title link and the title of the document.
Result

I have been working on a solution to aggregate documents from sub sites to the top level site of SharePoint with the out of the box features. To accomplish this you will have to work with the Content Query web part of SharePoint.
The Content Query web part works great but it doesn’t look like a list view and that was the styling I wanted. So let’s get working and create the styling we want.
To get the content query web part to look like a list view you have to get trough the following steps:
Step 1
Enable the “SharePoint Server Publication Infrastructure” feature if you haven’t already got the feature enabled. This feature makes sure you have the “Content Query” web part available within the web part gallery.
SharePoint-Server-Publishing-Infrastructure
Step 2
Go to the page were you would like to display the “Content Query” web part and place it on the page. The web part can be found under the “Content Rollup” category.
Edit the web part and specify the query you would like to preform. If you have specified the query save the web part and export it.
Note: if you want to query a certain type of content and this content is available within the subsites but not on the root you can not use the UI to create the query. If you want to use the UI you have to make the type available within the root site.
Webpart-Export
Step 3
You can add your custom columns to the query. This can be accomplish by editing the “CommonViewFields” property of the web part:
1
<property name="CommonViewFields" type="string">LinkFilename,Text;Title,Text;</property>
The value of the property must be in the following format [InternalName],[Type];[InternalName],[Type];
Step 4
If you would like to read out those properties by a more meaningful name you can change the “DataColumnRenames” property. This property will take care of the renaming for us.
1
<property name="DataColumnRenames" type="string">Title,Title;LinkFilename,Name</property>
The value of the property must be in the following format [InternalName],[New Name];[InternalName],[New Name];
Step 5
Now that we have defined our columns we will need to edit the xslt template to render the columns. We will have to open SharePoint Designer and open the Style Library of the site.
SharePoint-Designer
First we will edit the “ContentQueryMain.xsl” file. Within the file find the following line (79):
<xsl:template name=”OuterTemplate.Body”>
Within this template a call will be made the ItemTemplate. Within the call we will have to pass a new parameter called “LastRow” so that we know when we will have to close our grid.
For this search for the following lines (128):



<xsl:call-template name="OuterTemplate.CallItemTemplate">
    <xsl:with-param name="CurPosition" select="$CurPosition" />
</xsl:call-template>
And change it to:




<xsl:call-template name="OuterTemplate.CallItemTemplate">
    <xsl:with-param name="CurPosition" select="$CurPosition" />
    <xsl:with-param name="LastRow" select="$LastRow" />
</xsl:call-template>
Now that we pass the parameter we also have to change the template to accept the parameter.
Go to line 147 and you see the “CallItemTemplate”. Copy the second line and past it directly beneath it and make it look like this:



<xsl:template name="OuterTemplate.CallItemTemplate">
<xsl:param name="CurPosition" />
<xsl:param name="LastRow" />
Because we want to use this within our custom item template we also have give the parameter through to the template by adding a when statement just before the <xsl:otherwise> within the CallItemTemplate:






<xsl:when test="@Style='SPGrid'">
 <xsl:apply-templates select="." mode="itemstyle">
  <xsl:with-param name="CurPos" select="$CurPosition" />
  <xsl:with-param name="Last" select="$LastRow" />
 </xsl:apply-templates>
</xsl:when>
In this statement we specify that it only has to pass-through the parameter when the item template is SPGrid. So our custom template is going to be called “SPGrid”.
Step 5
Now it is  time to edit the “ItemStyle.xsl” file. Within this file we add our custom xslt item template:



























































<xsl:template name="SPGrid" match="Row[@Style='SPGrid']" mode="itemstyle">
    <xsl:param name="CurPos" />
    <xsl:param name="Last" />
 
    <xsl:variable name="SafeImageUrl">
      <xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
        <xsl:with-param name="UrlColumnName" select="'ImageUrl'"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="SafeLinkUrl">
      <xsl:call-template name="OuterTemplate.GetSafeLink">
        <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="DisplayTitle">
      <xsl:call-template name="OuterTemplate.GetTitle">
        <xsl:with-param name="Title" select="@Title"/>
        <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="LinkTarget">
      <xsl:if test="@OpenInNewWindow = 'True'" >_blank</xsl:if>
    </xsl:variable>
 
    <xsl:variable name="tableStart">
      <xsl:if test="$CurPos = 1">
       <![CDATA[
        <table width="100%" class="ms-listviewtable" cellpadding="1" cellspacing="0" border="0">
          <tr class="ms-viewheadertr ms-vhltr">
            <th class="ms-vh-icon"></th>
            <th class="ms-vh2">Name</th>
          </tr>]]>  
      </xsl:if>
    </xsl:variable>
 
    <xsl:variable name="tableEnd">
      <xsl:if test="$CurPos = $Last">
        <![CDATA[ </table> ]]>
      </xsl:if>
    </xsl:variable>
 
    <xsl:value-of select="$tableStart" disable-output-escaping="yes"/>
    <tr class="ms-alternating ms-itmhover">
      <td class="ms-vb-icon">
          <xsl:if test="string-length(@DocumentIconImageUrl) != 0">
            <div class="image-area-left">
              <img class="image" src="{@DocumentIconImageUrl}" title="" />
            </div>
        </xsl:if>
      </td>
      <td class="ms-vb2">
        <a href="{$SafeLinkUrl}" title="{@LinkToolTip}">                  <xsl:value-of select="$DisplayTitle"/>
        </a>
      </td>
      <td>
        <xsl:value-of select="@Title"/>
      </td>
    </tr>
    <xsl:value-of select="$tableEnd" disable-output-escaping="yes"/>
  </xsl:template>
The displayed xslt has to be placed just above the closing </xsl:stylesheet> tag. This xsl creates a template for each item and will display the icon , the title link and the title of the document.
Result