Translate

Friday, June 25, 2010

FBA Users in SharePoint 2010

One of our sites scheduled for upgrade to SharePoint 2010 uses Forms Based Authentication (FBA). Various blogs can be found on how to set up SharePoint 2010 to connect to a FBA database. But, one critical difference is how the new Claims Based Authentication (FBA in SP2010 speak) hands over an Idenentity to SharePoint 2010.

The change from integrated security to a Claims Based is basically this: In Claims Based mode, the SharePoint site no longer handles verifying Identities; that is handled through the new Security Token Service (STS). Previously a user's integrated FBA Identity was something like "FBAMembership:EtherDragon" now, in 2010, the STS hands over my Identity with something like "i:0#.f|FBAMembership|EtherDragon" and, as far as 2010 is concerned, that is a different user.

The fix was to write a quick Web Part for 2010 that replaces all FBA user Identities in all groups with the correct STS one.

Here's some code:
(Code)
SPWeb oWeb = SPContext.Current.Web;

foreach (SPGroup myGroup in oWeb.Groups)
{
string wrongFormat = "fbamembership:";
SPUserCollection myUsers = myGroup.Users;
List usersToDelete = new List();

foreach (SPUser userCandidate in myUsers)
{
if (userCandidate.LoginName.Length >= wrongFormat.Length)
if (userCandidate.LoginName.Substring(0, wrongFormat.Length) == wrongFormat)
{
usersToDelete.Add(userCandidate);
}
}

foreach (SPUser myUser in usersToDelete)
{

string loginName = "i:0#.f|fbamembership|
" + myUser.LoginName.Substring(wrongFormat.Length);
string eMail = myUser.Email;
string name = myUser.Name;
string notes = myUser.Notes;

myGroup.RemoveUser(myUser);
myGroup.Update();
myGroup.AddUser(loginName, eMail, name, notes);
myGroup.Update();
}
}
(End Code)

Without this little code block, we would have had to go through about 2000 user entries in various groups to remove and replace the users through the SharePoint UI.

Wednesday, May 5, 2010

"The specified file is not a valid spreadsheet or contains no data to import"

Here's the problem:

You try to create a custom SharePoint list using the Import Spreadsheet function and get an error, "The specified file is not a valid spreadsheet or contains no data to import"

The problem is that IE doesn't have access to your file system, and in this instance, it needs it. The solution is to add the SharePoint site to your Trusted Sites zone.

Go to Tools / Internet Options
Click on the Security Tab, hightlight Trusted Sites and click the Sites button.
Enter the URL of the SharePoint site and click the Add button.
Close and Save your settings. You can now impor the spread sheet.

Wednesday, March 24, 2010

Making Title Fields More Useful with InfoPath 2010

One of the challenges 4QTRS has had was determining how to best use the “Title” field in a given SharePoint list. Many lists, such as “Tasks” can use “Title” very naturally, using the title to give a few words to describe the item; i.e. “Run Server Updates.” But, other titles don’t make a lot of sense. “Last Name” is a field that can be adapted for the title field, indeed, the contact list changes the title field display name to “Last Name” for readability.

 
Consider a simple in/out log. The list leverages the already existing “Created By” field to determine who records in/out status, as well as the existing “Created” date/time field to log the in/out change. In this case, having a person enter anything into the “Title” field would be superfluous and open the process up to errors. So, we’re going to have the form automatically populate the title field and hide it from the user.

 
Start by opening up InfoPath 2010 and creating a new SharePoint List Form.

 

After authenticating to the site, and entering “InOutBoard” as the new list name, we see the default InfoPath form. Add a field called “Presence” and change the choices “In” and “Out” only.

 

Next, we will simplify the form to an easy two-button layout using the InfoPath designer. Our new buttons will each have a rule that runs on click that will handle all the work for us, including making sense of the otherwise useless title field.

 
Start by wiping the form, and creating a new centered layout section. Place a simple table within the layout and add two buttons; one each in the left and right cells. Change the buttons to read “In” and “Out” and delete the remaining table rows. Your form should look like this:


 
Now, we need to add four rules to the In button to complete the data entry.
  1. Set a field’s value: Presence = “In”
  2. Set a field’s value: Title = concat(userName(), " In at ", now())
  3. Submit using data connection
  4. Close this form

Configure a similar set of rules for the Out button, changing the two occurrences of the word “In” to “Out” and publish the form.

 
Click the Add new item link bring up the new form. We can click either button to enter an in/out log item into the list. Most importantly, the title field populates with useful information; “etherdragon In at 2010-03-24T11:25:39”

 
Improving the form further by changing the simple buttons to image buttons. Here is my finalized form using two simple image buttons.