Wednesday, March 26, 2008

Close Individual SharePoint Blog Posts for Comments


In a recent Extreme Makeover class, a student asked how they could close a Post in a SharePoint blog site for comments. They still wanted users to be able to read the blog post and read existing comments, but they didn't want them to be able to post comments on it. Kevin Pine and I worked together to create the following solution using some JavaScript in a Content Editor Web Part on the Posts.aspx page.

Add a Custom Column to the Posts List to Allow Comments

We needed some way for the blog owners to indicate when a post had been closed. On the Posts list, we added a new column named Allow Comments. We set the Type as Yes/No (check box) and the Default Value to Yes.

Update the Posts.aspx Page to Show the Value of the Allow Comments Column

Users can only submit comments while reading an individual post. This view of a blog post is generated by the Posts/Posts.aspx page. I clicked on the title of one of my blog posts to view the post in this page.

The Post Footer is displayed at the bottom of the post and above the comments section.

We needed the value of our new Allow Comments field to show up in the Post Footer. To accomplish this, we edited the current view by doing the following:

  1. Click on Site Actions, Edit Page.
  2. On the Posts web part, click on edit, Modify Shared Web Part.
  3. In the task pane, click on Edit the current view.

  4. Check the box beside Allow Comments, and click OK.

  5. View the blog post again and notice that the Allowed Comments value is now visible in the Post Footer.

Add the JavaScript to Hide the New Comment Fields If the Post is Closed for Comments

The form to submit new comments only appears on the Posts/Posts.aspx page. This means that we can add some JavaScript to this page to hide it if the phrase Allow Comments: No appears in that bottom line. Here is what we did to get the JavaScript on the page.

  1. While viewing a post in the Posts/Posts.aspx page, click on Site Actions, Edit Page.
  2. In the Right Web Part Zone, click on Add a Web Part.
  3. Select the Content Editor Web Part.
  4. Click the link to open the tool pane.
  5. Click on the Source Editor button.
  6. Paste in the following JavaScript code and click the Save button. Note that the code is fairly well commented if you are interested in what it is actually doing.

    <script language="JavaScript">
    //add an entry to the _spBodyOnLoadFunctionNames array

    //so that our function will run on the pageLoad event

    _spBodyOnLoadFunctionNames.push("hideComments");


    function hideComments() {

    //Create an array to store all elements to which

    //the ms-PstFooter class have been applied

    var PostFooterArray = getElementsByClass('ms-PostFooter');


    //Check to see if the first element of the array contains

    //the text "Allow Comments: No"

    if(PostFooterArray[0].innerHTML.indexOf('Allow Comments: No')!= -1){

    //create an array to store the SPAN tag with the ID of part1

    var commentSPAN = document.getElementById("part1");

    //Replace the comment form controls with my own HTML statement

    commentSPAN.innerHTML = '<b>Comments have been closed on this post.</b>';

    }

    }


    function getElementsByClass(theClass) {

    //From: http://www.seandempsey.com/code/getElementsByClass.php

    var allPageTags = new Array();

    //Populate the array with all the page tags

    allPageTags=document.getElementsByTagName("*");

    var Elements = new Array();

    //Cycle through the tags

    var n = 0;

    for (i=0; i<allPageTags.length; i++) {

    //Pick out the tags with our class name

    if (allPageTags[i].className==theClass) {

    Elements[n] = allPageTags[i];

    n++;

    }

    }

    return Elements;

    }

    </script>

  7. In the tool pane, expand the Appearance section.
  8. Set the Chrome Type to None.
  9. Click OK to close the tool pane.
  10. Click Exit Edit Mode.

Testing the Solution

My first blog post had the check box for the Allow Comments field checked. I can see the fields to post a comment.

If I uncheck the Allow Comments field and view the post, I can see that the comments have been closed.


Sunday, March 16, 2008

Changing Host Header for the MySite Host


I was playing around with SharePoint on my virtual machine and had set up a new installation of MOSS when I noticed I had entered a host header incorrectly (at least incorrectly from the standpoint of being consistent with my previous installations). I entered "MySite" instead of "MySites" as the first part of the host header. I know, I know, it's probably more correct to use the singular, but I was trying to be consistent with what others had done.
All I wanted to do was to change the host header and have SharePoint recognize the change. I performed the standard internet search and didn't get instant gratification, so I started playing around. I found that making the changes in three places and an IISRESET seemed to take care of my problem.
First, in Central Administration under Operations, Global Configuration, Alternate access mappings, edit the internal URL.


Next, open up IIS Manager and select the properties of the MySites web app. Change the host header by clicking on the Advanced… button.


Again in Central Administration, navigate to the Shared Services provider and click on My Site settings in the User Profiles and My Sites section. Change the personal site provider URL.


Perform an IISRESET. All should be well.

Monday, March 10, 2008

Get a Virtual PC image with SharePoint Solutions software pre-installed


Now you can download a Virtual PC hard drive image (VHD) with a forms-based SharePoint Extranet AND our entire software product line already installed and pre-configured for your evaluation. This downloadable virtual hard-drive image is pre-installed with:


  • SHAREPOINT SOLUTIONS EXTRANET COLLABORATION MANAGER
  • SHAREPOINT SOLUTIONS SITE PROVISIONING ASSISTANT
  • SHAREPOINT SOLUTIONS ALERT MANAGER 2007
  • MICROSOFT WINDOWS SERVER 2003 R2 ENTERPRISE EDITION
  • MICROSOFT SQL SERVER 2005 ENTERPRISE EDITION
  • SERVICE PACK 1 FOR MICROSOFT SQL SERVER 2005
  • MICROSOFT OFFICE PROFESSIONAL 2007
  • MICROSOFT OFFICE SHAREPOINT DESIGNER 2007
  • MICROSOFT WINDOWS SHAREPOINT SERVICES 3.0
  • MICROSOFT OFFICE SHAREPOINT SERVER 2007
  • MICROSOFT .NET FRAMEWORK 2.0
  • MICROSOFT .NET FRAMEWORK 3.0

The VHD evaluation images are designed to last for 30 days from the date the virtual machine is first run. After 30 days the image and all the software on the image will expire. Free registration is required for download.

Tuesday, March 04, 2008

Update from Microsoft SharePoint Conference 2008


By all accounts, Microsoft SharePoint Conference 2008 is a resounding success. There seems to be a lot of enthusiasm from both attendees and exhibitors alike.

Here's a photo of our SharePoint Solutions' booth:




Our session yesterday on SharePoint Extranets and FBA was standing-room-only. Here's a photo of myself presenting:

Monday, March 03, 2008

SharePoint and Office 14: Looks like I may have guessed right for once


For once, it looks like I may have guessed correctly about some enhancements we can expect in the next version of Microsoft SharePoint and Office: Office 14.

Three weeks ago, I was the keynote speaker at the SharePoint Information Worker Conference 2008. In my keynote, I gave my best guess at some of the enhancements we might see in the next version of SharePoint (expected sometime in late 2009).

Today, while listening to Bill Gates' Keynote address at the Microsoft SharePoint Conference in Seattle, I was pleasantly surprised to hear that I may have guessed right on my #1 prediction.

Gates said that a top priority for the next version of SharePoint is to beef up SharePoint Lists. SharePoint's List features don't sound as sexy and appealing as some of its other features, such as BI and the Business Data Catalog, but Lists are really the bedrock of the product and have proven to be a breath of fresh air to information workers who previously had to rely on Excel spreadsheets and Access databases for their seemingly endless need for tracking applications.

Unfortunately, so far SharePoint's List features have not been robust enough to develop true database applications. Fundamental features that application developers have come to expect in a relational database management system have been absent so far in SharePoint Lists due to a layer of architecture between SharePoint Lists and the underlying DBMS, SQL Server.

As I understood Gates today, that is all going to change in the next version of SharePoint. In the next version, SQL Server will "understand" SharePoint Lists and it will be possible to create a List that will, in effect, create a native table in the SQL Server database. Furthermore, because it is native, this will allow developers to make use of the more robust features of the DBMS and will eliminate the current performance issues with SharePoint Lists that have over 2000 rows.

In my mind, this improvement will also open the door for thousands of ISVs to port their vertical market applications to SharePoint as a platform, if they choose to do so.

I think this is great news for SharePoint as a development platform.