Tuesday, August 07, 2007

Case Study: La-Z-Boy Collaborates with ExCM and SharePoint


La-Z-Boy has numerous business partners, vendors and licensees, and sharing information with organizations outside the company had become a major issue. Because SharePoint out-of-the-box only allows administrators to create user accounts and assign security roles, the IT department was faced with making business decisions about what information to make accessible to outside parties in critical areas such as intellectual property.

ExCM enabled La-Z-Boy to shift the burden from IT to line-of-business employees with expertise in specific areas who know what is appropriate to share with external parties, and let them manage the account-creation process.

Friday, August 03, 2007

Take Custom Action Upon SharePoint FBA User Login


Many of our customers have use cases where by they would like to take a specific custom action when an FBA (forms based authentication) user logs in to their SharePoint Extranet. Some examples may be to update a back-end CRM system, or redirect the user to a specific page. It is actually fairly simple to implement this logic. The Visual Studio project and source code for this article can be downloaded by clicking the download link at the bottom of this page.
First under the 12 hive, open the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS folder. Find the login.aspx file, and make a copy of it called CustomLogin.aspx. This will be our new user login page.
Next, open the web.config for your SharePoint application, find the <authentication/> element, and change it from:
    <authentication mode="Forms">
      <forms loginUrl="/_layouts/login.aspx" />
    </authentication>
to:
    <authentication mode="Forms">
      <forms loginUrl="/_layouts/CustomLogin.aspx" />
    </authentication>
Now, create a new Class Library project in Visual Studio, or alternatively download my sample project from the link below. Your project will need references to Microsoft.SharePoint.dll, Microsoft.SharePoint.ApplicationPages.dll, and System.Web.
Rename the automatically created Class1.cs to CustomLoginPage.cs. To save time and effort, the CustomLoginPage class will derive from Microsoft.SharePoint.ApplicationPages.LoginPage. Here's what the class should look like:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.Security;

namespace SPSolutions.Custom
{
    public class CustomLoginPage : Microsoft.SharePoint.ApplicationPages.LoginPage    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.login.LoggedIn += new EventHandler(OnLoggedIn);
        }

        // Fires after user has sucessfully logged in        void OnLoggedIn(object sender, EventArgs e)
        {
            // Get the user            MembershipUser user = Membership.GetUser(this.login.UserName);

            if (user != null)
            {
                // Do something interesting such as redirect or update CRM            }
        }
    }
}
As you can see, it is a simple matter of subscribing to the base page's login control's LoggedIn event, and then taking action when that event fires. Inside the event handler, you can instantiate a MembershipUser object for the newly logged in user, and then do something interesting.
It should also be noted that the login control has three other events which may be salient to your particular use case.
  • LoggingIn - Occurs when a user submits login information, but before authentication takes place.

  • Authenticate - Occurs when a user is authentication takes place.

  • LoggedIn - Occurs when a user logs in to the web site, and has been authenticated.

  • LoginError - Occurs when a login error is detected.
Next, open the CustomLogin.aspx page created in the first step, and modify its Assembly and Page declarations to point towards the new custom code behind assembly. If you're using my sample project, your declaration will look exactly like this:
<%@ Assembly Name="SPSolutions.Custom, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e9db3057acd9c0f6"%> 
<%@ Page Language="C#" Inherits="SPSolutions.Custom.CustomLoginPage" MasterPageFile="~/_layouts/simple.master"%>
Finally, place the compiled assembly into the _app_bin folder of your SharePoint web application (e.g. C:\Inetpub\wwwroot\wss\VirtualDirectories\adventureworks.local.dev\_app_bin). Optionally, you could also place the assembly into the GAC.

Wednesday, August 01, 2007

Windows IT Pro Editor's Best of 2007 Award Goes to Extranet Collaboration Manager


Windows IT Pro magazine has given our Extranet Collaboration Manager product their Editor's Best of 2007 Award in the SharePoint category. ExCM is awarded on page 30 of this month's (August) Industry Excellence Awards edition of the magazine, which is also available online here.
During this process, Windows IT Pro magazine considered products for 13 different categories, including one category for Microsoft SharePoint. ExCM took first place for the SharePoint category, followed by Quest Software's (NASDAQ: QSFT) SharePoint Administrator product in second place, and Commvault's (NASDAQ: CVLT) Galaxy Backup and Recovery product in third place.
The editors of Windows IT Pro interviewed with members of our esteemed customer DraftFCB during their review. DraftFCB specializes in integrated marketing and advertising with an emphasis on branding, interactive, emerging media, multimedia, and database technology. Headquartered in Chicago and New York, the agency's network spans 180 offices in 110 countries serving clients such as Hewlett-Packard, Verizon, Computer Associates, Kellogg, and the United States Postal Service. The agency is led by chairman and CEO Howard Draft and is a subsidiary of Interpublic, the world's third-largest advertising conglomerate. DraftFCB is an early adopter of ExCM, and is actively using our product in their SharePoint 2007 Extranet.
No other free or commercial product on the market today offers the complete set of features available from ExCM. ExCM is platform certified by Microsoft and Veritest, and is used by both large and small companies from around the globe to enable their SharePoint 2007 based Extranets.

Thursday, July 19, 2007

Keyboard Shortcuts for SharePoint Calendars


If you use Sharepoint calendar views very much, you might be able to save some time, or at least impress your co-workers, if you control them via keyboard shortcuts. I was looking at the code view of the calendar web part earlier this week and noticed that several links had accesskeys assigned to them.

Here are the keyboard shortcuts for SharePoint Calendar views:
ALT + [ - Previous day, week, or month in a view
ALT + ] - Next day, week, or month in a view
ALT + X - Expand all
ALT + P - Collapse all
ALT + . - Switch to Day view
ALT + - - Switch to Week view
ALT + = - Switch to Month view

Hitting these keys in Internet Explorer will select the link--you will need to hit the ENTER key afterwards to activate the link.

Microsoft has also provided a complete list of SharePoint Keyboard shortcuts.

UforB: New European Reseller for SharePoint Solutions Software


I'm happy to announce that we've added Utilities for Business as an authorized reseller of our software products in Europe. Marco Linders of UforB has been a friend of our software division of a few years now, helping us with language translations and sage advice on how things work across the Atlantic. We've seen an explosive growth of interest in our software products worldwide, particularly in the European market. Marco and UforB will help us to deliver the best possible service and support to our European customers.

Utilities for Business provides solutions for:
  • SharePoint Web Parts
  • Internet solutions
  • Business Intelligence
  • Interactive visual reports
  • Management Information Systems
When you get a chance, please stop by UforB's website and drop Marco a message.

Thursday, July 12, 2007

Creating Workflows for Windows Sharepoint Services and MOSS2007 - a Step by Step Tutorial by Serge Luca.


Serge Luca [MVP WWF] has begun publishing a comprehensive tutorial titled Step by Step Tutorial. Creating Workflows for Windows Sharepoint Services and MOSS2007.

Serge's article is well-written and well-illustrated. It looks like three of twenty articles have been published so far, but clearly his complete article will be an authoritative guide worth bookmarking for future reference.

Wednesday, July 11, 2007

Overcoming Challenges in Modifying and Adding Page Content with JavaScript


If you've been wishing that more web parts gave you the option to apply XSLT styles, then the methods presented in this post may just be your ticket to the customization that you're seeking!It's not the same thing, but with some clever JavaScript coding, you can achieve similar results.

I'm a frequent user of Zap Reader—the popular, and free, web based speed reading program. There were already plugins for several blogs (WordPress, Blogger, and TypePad), but nothing for SharePoint blogs. I thought it would be nice to add a button to each blog post that allowed readers to quickly load the text into Zap Reader so they could speed read it.

Conventional wisdom would have said that this needed to be written in Visual Studio and then installed as a feature that could be activated or deactivated for each blog site. Some of the existing Zap Reader tools were already written in JavaScript, so I figured why not leverage this existing code base and write something that any Power User could easily add to their blog without having to go through all the IT Department red tape to get something extra installed. (I don't necessarily think all that red tape is a bad thing, I just figure why go through it if you don't have to.)

I started with the existing code for the Greasemonkey script that adds a "Zap Read This" button to each post in BlogLines—it worked essentially the way that I wanted this one to work: the page would load; the script would then rewrite each blog post on the page to include a "Zap Read This" button. It sounded good in concept, but I encountered a couple hurdles along the way. I'm hoping to save other JavaScript developers some trouble by documenting in this post how I overcame them. Note that many Greasemonkey scripts can be modified to work within a Content Editor web part to give all your users extra functionality on that page, regardless of the browser they are using. You may want to spend some time browsing http://www.UserScripts.org to get some inspiration, and code.

The DIVs for the blog posts don't have unique names.

Because I needed to extract the innerHTML for each post, modify it, and then write it back, I needed some way to consistently reference it. All the post DIVs did have the same "ms-PostBody" CSS class, however. To help with this, I found a nice JavaScript function called getElementsByClassName() by Jonathan Snook and Robert Nyman. Calling this function placed all the DIV objects with the "ms-PostBody" class in an array where I could work with them.

I couldn't add new FORM tags on the page.

If you've tried to add any code to a content editor web part that contained FORM tags, you got an error telling you, "FORM tags are not supported in the HTML specified in either the Content property or the Content Link property." At first I thought that would be no big deal since I was adding my tags dynamically using JavaScript to update the innerHTML of another DIV. When I tried this though, I got an "unknown runtime error" in the browser when my JavaScript ran.

I discovered that IE7 validates code that is written using the innerHTML property before it writes it, and if it is invalid markup, it will give you the "unknown runtime error". The reason that I was getting it was that almost the entire page was already wrapped in FORM tags (this is needed for all the cool out-of-the-box JavaScript functionality in SharePoint 2007) and you can't have one HTML form nested inside another one. That made sense. Since I couldn't add my form at each button, I decided to just utilize the existing form tags and have my script modify them when the button was clicked, and then change them back when the script was finished running.

You will find the code for the "Zap Read This" Button for SharePoint Blogs on the Zap Reader Tools page. The code is well documented to explain why I did some things the way I did. To use it, simply copy the code and paste it into a Content Editor web part on both the default.aspx and Lists/Posts/Post.aspx pages of your SharePoint Blog. You may want to customize the placement or look of the button, but this was written to give you just the basic functionality.

Let me know in the comments what you think!


 

Thursday, July 05, 2007

Changing the Number Of Blog Posts Per Page


When I posted about how to Select Multiple Categories for SharePoint Blog Posts, one reader noted in the comments that when you view items by category, it only lists 10 posts per page. This reader wanted to know how to increase the number of posts that are shown on a particular page.

Unfortunately, there isn't a quick and easy way to do this just from within a web browser. Our faithful friend, SharePoint Designer 2007 will give us the tools we need to change this, however.

First, click on one of the categories to go to the page that displays the posts for that category. The page should be at /Lists/Categories/Category.aspx. Now open this page for editing in SharePoint Designer 2007.

Once the page is open, change to code view. Then look for a section of code that looks like the following screenshot:


(Note: this screenshot was taken with Word Wrap enabled.)

You are looking for the section that is highlighted in the above screenshot.

You will see several other RowLimit sections with other numbers in them. You want to make sure you have this one.

Change the number "10" to however many blog posts you want to display on a page.

Once you've made your change, save the page and view it.

If you want to display more posts on the home page of your blog, you can do this same thing by editing default.aspx.

Adding JavaScript to a Content Editor Web Part to Run onLoad


Adding JavaScript to a page inside a Content Editor web part can be a great way to perform on-the-fly customizations to your SharePoint sites. This worked great in WSS v2 and SPS 2003. We started noticing that some of those scripts didn’t seem to work in WSS v3 and MOSS 2007, however, and it wasn’t because the names of objects and elements had changed.
For example, here is a JavaScript snippet that we had used to hide the “NEW!” icon on a page in WSS v2.
Note: In all code examples below, replace the square brackets around the SCRIPT tags with angle brackets. If I included the angle brackets, the browser tried to execute the code. :o(
[script language="JavaScript"]
var fields,i;
fields = document.getElementsByTagName('IMG');
for( i = 0; i < fields.length; i ++ ) {
  var imgsrc = fields[i].getAttribute('SRC');
  if(imgsrc.indexOf("new.gif") != -1) { 
   fields[i].style.visibility = "hidden";
  }
}
[/script]
When we added this to a Content Editor web part in a WSS v3 page, nothing seemed to happen. I added code to make it run on the onLoad event, and that didn’t work either. I did a little experimentation and discovered that if I added a short delay, even a delay of 1/1000 of a second, it worked fine. I placed the core code within a function and then called it with the setTimeout() method.
[script language="JavaScript"]
setTimeout(HideNewIcons,1);
function HideNewIcons(){
  var fields,i;
  fields = document.getElementsByTagName('IMG');
  for( i = 0; i < fields.length; i ++ ) {
    var imgsrc = fields[i].getAttribute('SRC');
    if(imgsrc.indexOf("new.gif") != -1) { 
     fields[i].style.visibility = "hidden";
    }
  }
}
[/script]
The problem occurs because most WSS v3 pages use a master page that contains the “body” element, and the page content code loads after the master page code. I didn’t know it at the time, but recently discovered (thanks to this article on the Microsoft SharePoint Products and Technologies Team Blog) that the SharePoint developers had given us a way to work around that issue—it’s the _spBodyOnLoadFunctionNames array. We can use JavaScript’s “push” method to load items into this array where they will run when the body’s onLoad event fires .
Here is what the JavaScript looks like with the setTimeout replaced with a line that pushes the function name “HideNewIcons” into the _spBodyOnLoadFunctionNames array.
[script language="JavaScript"]
_spBodyOnLoadFunctionNames.push("HideNewIcons");
function HideNewIcons(){
  var fields,i;
  fields = document.getElementsByTagName('IMG');
  for( i = 0; i < fields.length; i ++ ) {
    var imgsrc = fields[i].getAttribute('SRC');
    if(imgsrc.indexOf("new.gif") != -1) { 
     fields[i].style.visibility = "hidden";
    }
  }
}
[/script]
If you’ve been having trouble getting some of your legacy JavaScript scripts to run from within Content Editor web parts in WSS v3 or MOSS 2007 pages, give this technique a try, and let me know if it works for you.