Skip to main content

Click Mice, Unclick Mice

Go Search
Home
Wikin
Windows Live ID Authentication
  

Click Mice, Unclick Mice > Categories
SharePoint Designer videos
I worked on a series of video topics for SharePoint Designer.  The videos cover a pretty wide range of SPD functionality.  Most of the videos are around 5 minutes long so if you are looking for a quick intro in to how to do something in SPD it may be worth a look.  There are about 20 topics from data sources to workflow.  You can find them here:
 
 
 
What is Missing in the SharePoint Blog Template (pt.2)
Here is Part 2 in our ongoing process to make some magic happen around the SharePoint Blog template.  If I had the announcer voice for it I would treat you all to a, "Last time on Click Mice, Unclick Mice...".  However, I think we will all have to settle for a quick recap in text. 
 
In the last post we went through the process of using SharePoint Designer to codelessly set up a web part that would give us Archive links grouped by month and year.  We had set ourselves a few requirements as goals:
  1. Navigation component that shows the Month and Year with the number of posts for that timeframe
  2. Let's make the navigation component expandable so it can show links to the posts if people choose to expand it
  3. Should appear on every page in the same position
  4. Should adhere to the theme that is on the page at the time (i.e. if I change themes it should update to reflect that)
  5. If I click on the Month Year heading it should display a filtered list of the posts for that month

We covered them all in the last post except the last one.  We did setup the Archive links web part to point to a view page, but we did not create the page...yet.  So now we have part two where we will complete requirement #5.

Series Links

What is Missing in the SharePoint Blog Template (pt. 1)

Filter View By Month and Year

This functionality doesn't exist on a normal date time field out of the box, but we have the power of XSL backing us so I don't think there will be a large problem.  Solving this particular problem seems like it will be much simpler than the Archive links web part, especially since we only have one requirement to fill (technically two since we want this to occur codelessly as well).

This post isn't as long as the last, but for those of you who are impatient you can find the finished product here.  You will need to create your own By Month.aspx view page in your Posts list, but then you can just drag this web part on to it.

Making It Happen

Since we are keeping the mantra of codelessly created in mind, we will go to my friend SharePoint Designer again, and we are going to follow the same precepts as the first post.  We will take a List View and modify it until it resembles what we want as closely as possible, then we will convert it to a Data View.

Section 1 - Configure And Convert A List View

Taking a step back, it should be fairly apparent that all we really need to do is take the Posts web part from the Home page (default.aspx) and add some custom filtering to it.  We will also need to create a List View Page to hold our new view.  We should be able to create our new view page with a few clicks inside SharePoint Designer.

  1. Right-click on the Posts web part and select Copy (Fig 1.1)
  2. Expand the Lists and Posts folders in the Folder List pane (Fig 1.2)
  3. Right-click on the Posts folder and select New -> List View Page
  4. Name it By Month and click Ok
  5. Right-click the Posts web part on the new view page and select Paste (Fig 1.3)
  6. Right-click the Posts web part and select Convert to XSLT Data View (Fig 1.4)

Figure 1.1
Figure 1.2
Figure 1.1
Figure 1.2

Figure 1.3
Figure 1.4
Figure 1.3
Figure 1.4

We actually want to keep the exact same view as the home page, we just want to add some filtering so we have gone as far as we are going with the List View web part.

Section 2 - Setup Data View Parameters

Now that we have our Data View page showing us the data that we would like, we need to prepare the Data View for filtering. 

  1. Once converted by default you should see the Common Tasks menu, click the Parameters... link (Fig 2.1)
  2. Click the New Parameter button
  3. Give the new parameter a Name of Month
  4. Make sure the Month parameter is highlighted, change the Parameter Source drop down to Query String and the Query String Variable to Month (Fig 2.2)
  5. Click the Ok button

Figure 2.1
Figure 2.1

Figure 2.2
Figure 2.2

Now we have all the raw data we need for our Data View.  Adding this parameter has given us the ability to pass a value in to the web part from the Query String, and in part one we have our Archive headings passing in the group heading as the Month query string parameter.

Section 3 - Change The DataSet

Since we have our raw data, it is time to shape it in to the finished product that we need.  We will need to go in to the Code View in order to accomplish what we want in our filtering. I can imagine what you might be thinking, there is a perfectly good filter option in the Common Data View Tasks menu.  My answer is yes, there is a Filter option in the Common tasks menu, however it does not allow us to accomplish our end goal.  The Filter option is better suited to matching exactly, or at least a portion of, the content in a column.  We need to match against a set of column data that requires some transformation (our date string needs to be transformed to month year format).

  1. Click in to the Code View and type Ctrl-F to start a Find
  2. Search for /dsQueryResponse/Rows/Row (Fig 3.1)
  3. Change /dsQueryResponse/Rows/Row to /dsQueryResponse/Rows/Row[ddwrt:FormatDateTime(string(@PublishedDate), number($Language), 'MMMM yyy')=$Month] (Fig 3.2)
  4. You will see a message that there are no posts, and below that you will see the original Posts web part that was on the page
  5. Right-click the web part and select Cut
  6. Press Ctrl-S to save the changes

Figure 3.1
Figure 3.1

Figure 3.2
Figure 3.2

Section 4 - Extra Credit

In the first post of the series, I handed out extra credit to make the Data View web part reusable outside of an STP file.  I will extend it here as well.  The instructions for making a Data View portable are here.

Wrap Up

So we started out in part one with 5 requirements, and we now have a system of two web parts that fulfill our requirements.  SharePoint does give the flexibility to build almost anything from its raw materials.  Looking forward to future posts in the series I am not sure what I will try to tackle next.  I may see what I can do for Most Active posts, or maybe how to codelessly add in links to social networking websites (like http://del.icio.us/ and http://digg.com/).

What is Missing in the SharePoint Blog Template (pt.1)
I had created the Wikin site template to overcome some of the perceived shortcomings of the out of the box SharePoint Wiki site template.  I made it in to an STP because there were a couple of people who wanted something easy to deploy on their SharePoint farms.  I have decided that I have a much more personal investment in looking at the out of the box Blog template.
 
Recently, I have been looking around and checking what the general feel for the SharePoint Wiki and Blog functionality is.  I have to say, in general the feedback wasn't positive, at least what I read.  As I read more and thought about it, the core issue was that SharePoint is really a development platform.  Granted, Microsoft will have some feature functionality that completes all your hopes and dreams, but what it doesn't give you on a platter you can create from the platform.
 
So we get to the point, since I am blogging I want what other blog software has.  I mean, who doesn't want what the other guy has, right?  I am willing to invest a little time to get what I want.  So this is part one in an open ended number of posts that will work to create new blog functionality from the building blocks of the platform without custom code.
 
Series Links
 
Proper Archive Links
The frst thing I notice that just seems missing is a proper set of Archive links.  I mean, don't get me wrong, there is a link out of the box, but where is the elegance in a link to the "All Items" view?  So the first problem is how to make this happen.  It shouldn't be too big of a deal, lets break it down to what I need:
  1. Navigation component that shows the Month and Year with the number of posts for that timeframe
  2. Let's make the navigation component expandable so it can show links to the posts if people choose to expand it
  3. Should appear on every page in the same position
  4. Should adhere to the theme that is on the page at the time (i.e. if I change themes it should update to reflect that)
  5. If I click on the Month Year heading it should display a filtered list of the posts for that month

This is a really long post, so for those of you that are impatient you can find the finished product here.

Making it Happen

Since we are doing this with the mantra of no custom code, that gives me two choices for how to make this happen: the List View web part and Data View web part.  List View is too restrictive so I am going to punt on that and we'll do this as a Data View.

Section 1 - Configure And Convert A List View

The first step is to load up the site in SharePoint Designer.  It happens to be my favorite editor for this kind of thing, and so that is what I'll be using.  Now once Designer is open, I am going to add a Posts list view web part.  I can feel you scratching your head, wondering if I remember that about a paragraph ago I was going to use a Data View.  I am, but the SharePoint Designer team has done a lot for me already in terms the #4 requirement on the theme.  If I convert the List View web part to a Data View, it will keep the CSS settings of the List View.  On the other hand, if I start from a fresh Data View I have to go through and setup the proper table and CSS structure to get everything to look consistent.  So the next step is to get the List View showing what I want.  In this case, it is the Title column grouped by the Posting Date.  To do this I will:

  1. Bring up the context menu and select the Fields option (Fig 1.1). 
  2. Setup the columns to the Title field I would like (Fig 1.2).  
  3. Bring up the context menu and select the Change Layout option (Fig 1.3). 
  4. Setup the List View options I would like (Fig 1.4)
  5. Bring up the context menu and select the Sort and Group option (Fig 1.5). 
  6. Setup the columns to the Sort order and Group by properties I would like (Fig 1.6)
  7. Right-click the List View and convert to a Data View (Fig 1.7).

That is as close as I am going to get with the List View. 

Figure 1.1
Figure 1.2
Figure 1.1
Figure 1.2

Figure 1.3
Figure 1.4
Figure 1.3

Figure 1.4

Figure 1.5
Figure 1.6
Figure 1.5
Figure 1.6

Figure 1.7
Figure 1.7

Section 2 - Modify The Data View Look And Feel

Now we have ourselves a Data View that is close, but still pretty far away from what we want.  We have our view set to group by posting date, but not by month and year yet.  So it is time to get our hands dirty with the Data View. 

  1. The easiest way to work is through the design surface so we start by right clicking next to the Title  column header and selecting Delete -> Delete Rows (which is not needed since we are going to be doing a lot of grouping and things really should already be sorted by published date) (Fig 2.1)
  2. We need to change the Group Heading for our published dates.  We can't have it saying Published: MM/DD/YYYY that just won't do.  Click on the first Published xsl:value-of element and just press delete 6 times (this is going to delete the Published column title text and the colon leaving us with just the date).
  3. We are close to where we want to be now; all that we are missing is a count of the grouped items.  Luckily, this one is easy.  We will just click on the date in the design surface, which will highlight a portion of the Code View.  Then we'll paste in (<xsl:value-of select="count($nodeset/@Title)" />) which will give us a count of the number of items passed in to the template (Fig 2.2)
  4. The last change that is required will give us the setup for requirement #5.  We will need to setup a custom view for this, but knowing ahead of time what we need allows us to plan for it.  Once again, we are going to click on the first date to get our place in the Code View.  Now we will paste in <a href="{concat(substring-before(@FileRef, '/Posts/'), '/Posts/By%20Month.aspx?Month=', $fieldvalue)}"> which will be our link to the custom view we will need to make.  Essentially, it is a view that will be in the Posts list and it will have a query string with the value of our Group Heading.  Now we close off the <a> tag at the end of the Group Heading (Fig 2.3).

 That completes our Look and Feel changes.

Figure 2.1
Figure 2.1
Figure 2.2
Figure 2.2
Figure 2.3
Figure 2.3

Section 3 - Change The DataSet

So now we have updated how the XSL template for each group heading is handled.  Next we need to get the data to actually be grouped properly.  By default our list view has automatically grouped our data by posting date.  So we just need to modify what it has done, to group by posting month and year instead.  There are three main areas we need to change. 

The first is the NewGroup_0 variable which we will track down by doing a Find for NewGroup_0.  The Code View should show the xsl:variable tag, and inside there is a xsl:when that contains a xsl:value-of tag.  This is our first taget.  This will start our group creation so we will need to change the select statment.  By default you will see it checking if the Published date has changed.  We'll alter the XSL to this ddwrt:NameChanged(ddwrt:FormatDateTime(string(@PublishedDate), 1033, 'MMMM yyy'), 0) which checks to see if a formatted date string of the published date has changed (Fig 3.1)

The next target is the groupheader0 xsl:variable which is located just a few lines below the NewGroup_0 variable.  This one has a xsl:otherwise with a xsl:value-of tag.  This will set our group header text so this select statement will be changes to ddwrt:FormatDateTime(string(@PublishedDate), 1033, 'MMMM yyy') which will set it to the formatted string we used when we changed the previous select statement (Fig 3.2)

Our last target is in the xsl:call-template for dvt_1.groupheader0 which is just below the groupheader0 variable.  There is a xsl:with-param with a name of nodeset that we need to change the select statement for.  We will change it to msxsl:node-set($dvt_Rows)/root//Row[((ddwrt:FormatDateTime(string(@PublishedDate), 1033, 'MMMM yyyy'))=$groupheader0 or ((not(ddwrt:FormatDateTime(string(@PublishedDate), 1033, 'MMMM yyyy')) or ddwrt:FormatDateTime(string(@PublishedDate), 1033, 'MMMM yyyy')='') and $groupheader0=' '))] which will select the data based on the formatted date string of its published date matching our group header (which is in Month Year format) (Fig 3.3).

Figure 3.1
Figure 3.1
Figure 3.2
Figure 3.2
Figure 3.3
Figure 3.3

Section 4 - Putting It Into Play

Well we actually have our Data View all setup now.  We can save it and it will have everything we were hoping for except #3, but getting it in to the navigation is the easy part.  Right?  One would think so; however, the Blog template has some special characteristics around how its pages work.  There is a new web part zone added to a few pages called the BlogNavigator so you have to actually export the web part and add it to these pages in their BlogNavigator web part zone:

  • default.aspx
  • Lists/Posts/Post.aspx
  • Lists/Categories/Category.aspx

After you have done this, you will need to open up the master page and add it there as well for all of the pages that are not listed above (assuming you want to).

Section 5 - Extra Credit

With any Data View web part there comes a problem: how can I make it reusable?  I am only aware of two ways.  Either make the Data View a part of an STP file, and it should automatically find its new list when the new site is provisioned, or make changes to bind to a list name instead of a GUID.  This will also find the new list in a provisioned site and has the benefit of being able to be exported and used on anyone's system without them having to edit it.  The instructions for how to make those changes are here.

Wrap Up

So while SharePoint might not have the capabilities of some Blog software out of the box, you can see that it is possible to use the raw materials to fashion what you need, and in a lot of cases I think you will find that you can do it without having to write and deploy code.  There are many ways to do things codelessly inside SharePoint.  We will take care of requirement #5 in What is Missing in the SharePoint Blog Template (pt. 2).

Adding a Center web part zone
Had a few people asking me about how to modify their Team Site default.aspx to add a center web part zone.  Easiest way to accomplish this is using SharePoint Designer to make some changes.
 
  1. File -> Open Site (enter your site URL)
  2. Double-click to open the default.aspx
  3. You should see a Left and a Right web part zone and in between there should be a lonely looking TD tag
  4. Place your cursor inside that TD tag and click on Insert -> SharePoint Controls -> Web Part Zone
  5. Select your new web part zone using the top nav breadcrumb and use the drop down to select Tag Properties for your web part zone
  6. Change the settings to your liking and click Ok
  7. Now to align the zone properly select the TD tag that contains the web part zone and add set the Vertical Alignment to Top using Tag Properties
  8. Also specify the width in percent, I would suggest 25% however you may have other ideas based on what you want it to look like
  9. You will also need to adjust the width percentage in the TD tags that contain the Left and Right web part zones to make sure everything adds up to 100% (If you set the new center zone to 25% you would likely want the Right to be 25% and the Left to be 50%)
  10. File -> Save and you are done

Granted this only changes the default.aspx for one site, however you can always save the site as a template.  You could also go through the steps to create a new site definition based on the team site that updates the OOTB default.aspx, but that is a post all on its own.

Data View Web Parts bound to List Names
Know them and love them.
 
I was working on a custom Wiki template the other day and I wanted more than anything not to have to package it as a WSP file.  I was trying my best to come up with a way to use my nice custom list dataview web part in a STP file, but SharePoint Designer loves more than anything to put the list GUID in to the dataview which pretty much makes the STP file a no can do item.  Which really meant that I was going to be forced to use a WSP just to use this dataview and to be able to get it to point at the correct list when it was provisioned.  I was just a little put off by the whole thing so I walked away from it for the night.
 
It was a bright and shining new morning though when I stumbled on a new piece of information.  SharePoint Designer had led me astray and had neglected to mention a new feature in the dataview.  They can be bound by List Name.  Maybe this isn't news to everyone, but I certainly didn't get the memo. 
 
In order to make use of this new handy feature its a simple find and replace in SharePoint Designer or your Data View Web Part editor of choice. 
 
  1. Open the web part definition in your editor of choice
  2. Look for all occurances of ListID in the web part definition and right next to that you should see a GUID. 
  3. Replace ListID with ListName and the GUID with the list name you want to bind to. 

I felt the need to share because this is something I wanted since WSSv2 and I had no idea it made the cut until last week.