Thursday, November 13, 2008

SP2007: Infopath Usernames to a SharePoint Person or Group Column

SharePoint lists and document libraries can have their views filtered to only show items that relate to the current user if the [Me] filter is applied to a "Person or Group" column. When creating a form in InfoPath, it would be nice to be able to put usernames into a SharePoint Person or Group column to take advantage of this filter, but you cannot do that directly. A workaround is below...

The first thing required is to capture the usernames into a text field in InfoPath. They must be in a semicolon delmited string.
When publishing the form to SharePoint, make sure that column is also published as part of the content type.

In SharePoint, create your list with the content type from the InfoPath form, and add 2 more columns to it. One is a "Person or Group" column, set to allow multiple selections and People only. Check to add this one to the content type. The other is a single line of text column. Do not add this one to the content type.

Finally launch SharePoint Designer and open your site. Create a new Workflow for your list or document library that runs on adds and changes.
The Condition will be to check that the InfoPath text field "not equals" the SharePoint text field.
The Action is to Update Item in the list. Make the Person or Group field equal the InfoPath text field, and the make the SharePoint text field equal the InfoPath text field.

Basically what this does is use a workflow to copy the InfoPath text field with the usernames in it into the Person or Group field in SharePoint. As long as they are semicolon delmited and the usernames are in the SharePoint profiles this should work. The SharePoint text field saves the current value of the InfoPath text field, so if the list of usernames in InfoPath changes the workflow will know and re-run.

Thursday, October 23, 2008

SP2007: Adding Photos to the Contacts List

Adding photos to a Contacts List is very cumbersome. Your options are:
1) Add a picture column to the contacts list, create a picture library, upload your pictures to the picture library, and copy and paste the URL of each picture into the picture column in the contacts list... very cumbersome.
2) Create a Picture Library to use for contacts. Add columns for name, email, address, and phone. Add a picture of the user and then fill in the columns for their contact information. Just hope you never have to switch out a photo or you'll have to re-enter the contact info.
3) Use a Contacts List, and just attach the photos to each contact. This is the easiest to set up, but requires users to click to open the attachment to see the photo.

The third option is close, but the view needs to be improved.

Ideally if you attach a photo to a contact in the Contacts List it would be nice if that photo was displayted when you were viewing the contact's details. This can be done with a bit of javascript. Launch SharePoint Designer, edit the DispForm.aspx page, and add the following javascript. There may be better places to add this, but putting it in the content place holder "PlaceHolderBodyAreaClass" seems to work fine. It may not work with multiple attachments, and it could also be improved to only execute if the attachment is a jpg or gif, but that wasn't needed for this project.

<script>
if (document.getElementById("idAttachmentsTable").rows.length > 0)
{
myRow = document.getElementById("idAttachmentsTable").rows[0];
myHref = myRow.firstChild.firstChild.firstChild.href;
myRow.firstChild.firstChild.firstChild.innerHTML = '<IMG SRC="' + myHref + '">';
}
</script>

Thursday, July 10, 2008

SP2007: Date Only in View

Sometimes it might be useful to have a simplified View for a Document Library that only shows the Modified Date, instead of the Date and Time.

You can get this effect by creating a new Column, and setting it to the Calculated type. Calculated columns allow you to preform calculations similar to what you might do in Excel.

The formula you need to display the date only is:

=TEXT([Modified],"MM/DD/YYYY")

Changing the last part allows you to change how that date is displayed. For example, MM is a 2 digit month, while MMM is a three character month abreviation (Jan, Feb, Mar) and MMMM is the full month name.

Wednesday, July 9, 2008

SP2007: Custom Master Pages on Subsites

While MOSS contains an interface which should allow you to set the master page for all sites, this does not work in practice. Instead you can receive the message "The site master page setting currently applied to this site is invalid. Please select a new master page and apply it"
http://support.microsoft.com/kb/936908

To make this work, Microsoft suggests using a Feature to activate the publishing feature on all sites.
You don't have to turn on publishing for all subsites. Instead you can use a Feature to apply this master page to the appropriate sites.


To automatically apply the master page to the site it is helpful if you understand what Features are, and the Staplee and Stapler setup for applying Features.
http://msdn.microsoft.com/en-us/library/ms460318.aspx

In the Features folder, create 2 new folders
SubsiteStapler
SubsiteStaplee

SubsiteStapler
In the SubsiteStapler folder you'll have a feature.xml file and an element.xml file.

The feature.xml file sets up the feature. Note that ID is a unique guid. If you need this on several servers on the same farm you'll likely need different guids.

<Feature
Id="130ed937-2658-445e-9df3-34f40b9d702c"
Title="Subsite Creation Feature Stapler"
Scope="Farm"
xmlns="http://schemas.microsoft.com/sharepoint/" >
<ElementManifests>
<ElementManifest Location="elements.xml" />
</ElementManifests>
</Feature>

The elements.xml file tells MOSS what templates you are going to apply this feature to. Note that the ID listed on all of these lines is the same ID from the feature.xml file in the SubsiteStaplee Feature below. Basically you are using the Stapler feature to associate the Staplee feature with all of the templates listed. You can also add other templates (like your own custom ones)

<Elements xmlns="http://schemas.microsoft.com/sharepoint/" >
<FeatureSiteTemplateAssociation Id="bb77f112-2cda-4e92-b0ff-820c0216a7fe" TemplateName="STS#0"/>
<FeatureSiteTemplateAssociation Id="bb77f112-2cda-4e92-b0ff-820c0216a7fe" TemplateName="STS#1"/>
<FeatureSiteTemplateAssociation Id="bb77f112-2cda-4e92-b0ff-820c0216a7fe" TemplateName="STS#2"/>

<FeatureSiteTemplateAssociation Id="bb77f112-2cda-4e92-b0ff-820c0216a7fe" TemplateName="MPS#0"/>
<FeatureSiteTemplateAssociation Id="bb77f112-2cda-4e92-b0ff-820c0216a7fe" TemplateName="MPS#1"/>
<FeatureSiteTemplateAssociation Id="bb77f112-2cda-4e92-b0ff-820c0216a7fe" TemplateName="MPS#2"/>
<FeatureSiteTemplateAssociation Id="bb77f112-2cda-4e92-b0ff-820c0216a7fe" TemplateName="MPS#3"/>
<FeatureSiteTemplateAssociation Id="bb77f112-2cda-4e92-b0ff-820c0216a7fe" TemplateName="MPS#4"/>

<FeatureSiteTemplateAssociation Id="bb77f112-2cda-4e92-b0ff-820c0216a7fe" TemplateName="WIKI#0"/>

<FeatureSiteTemplateAssociation Id="bb77f112-2cda-4e92-b0ff-820c0216a7fe" TemplateName="BLOG#0"/>
</Elements>

SubsiteStaplee
In the SubsiteStaplee folder you'll need your master page (subsite.master) and a feature.xml and element.xml files


feature.xml

<Feature
Id="bb77f112-2cda-4e92-b0ff-820c0216a7fe"
Title="Subsite Creation Feature"
Scope="Web"
ReceiverAssembly="MySiteCreate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c726fa831b98198d"
ReceiverClass="Microsoft.IW.MySiteCreate"
Hidden="TRUE"
xmlns="http://schemas.microsoft.com/sharepoint/">

<ElementManifests>
<ElementFile Location="subsite.master"/>
<ElementManifest Location="element.xml"/>
</ElementManifests>
<Properties>
<Property Key="MasterName" Value="subsite.master"/>
<Property Key="CSSName" Value="/Style Library/customcss.css"/>
</Properties>
</Feature>


elements.xml

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="SubsiteStapleeFiles" List="116" Url="_catalogs/masterpage">
<File Url="subsite.master" Type="GhostableInLibrary" />
</Module>
</Elements>

You should also notice the CSSName Property Key in feature.xml, which in this case is set to a custom sytle sheet in the Style Library. Change this to point to your style sheet and you can apply a style sheet at the same time you apply a master page.

MySiteCreate.dll
You'll aslo need the application which staples the subsite.master to the templates. You can use the MySiteCreate.dll found in the MySiteCreate kit, which you may have already installed if you are using a custom master page on your My Sites. It was designed to staple a master page to a My Site, but can be used to staple a master page to any site.
http://www.codeplex.com/CKS/Release/ProjectReleases.aspx?ReleaseId=2824
Drop it in /Windows/Assembly.

Finally register the features in a Command Prompt window:

first change directory to where your stsadm.exe program is, then run the commands:

stsadm -o installfeature -name SubsiteStaplee
stsadm -o activatefeature -name SubsiteStaplee -url http://yoursite
stsadm -o installfeature -name SubsiteStapler

iisreset

Now whenever a new Subsite is created, the SubsiteStapler Feature will kick off the SubsiteStaplee Feature which uses the MySiteCreate.dll to apply the subsite.master Master Page to the subsite.

Friday, February 22, 2008

SP2007: I need to... Web Part

The web part "I need to..." states that it will display tasks and tools from a list. This little statement is deceptively simple, and there are a few requirements for the list before it will display. The "I need to..." name is also somewhat misleading.

This list you will point this web part at requires, at a minimum, a Title, a URL (Hyperlink or Picture) field, and a Choice field. You could start with a Tasks list and add a URL field, or you could start from scratch with a custom list. Part of your decision depends on how you want to use this web part and what fields it will need.

If you'd like the web part to simply be a nice compact list of links you visit on a regular basis, it is best to start with a Custom list. A new custom list will have a Title column by default, so you only need to create a URL and Choice column. Go into the list settings and create a new column called "URL". Make this a Hyperlink or Picture field. Next create a column called "Display". Make this a Choice type, with the possible choices of "Yes" and "No". Make the default value "Yes". Now you can point the "I need to..." web part at this list, and set the Filter Field to "Display" and the Filter Value to "Yes".

Once you make these changes you may need to close your browser and relaunch it.

Using a task list can give you some intersting options, as you can filter on the task status or priority, and then link the task to a website or document that you need to work on. Just start with a standard task list and add a new column called URL.

This paticular web part tends to keep things cached. Also you can only have one of these "I need to..." web parts on a page.

SP2007: Filtering a Calendar View by Start Time

For some unknown reason you cannot filter a Calendar by Start Time in a custom view. This is fairly odd, as it is a common request to filter out calendar events that have past.

A user named Dink posted this helpful tip at SharePointU

Create a new column named "Begin Date", make it calculated, add "=[Start Time]" in formula, return type of date and time, uncheck add to default view.
Create a new view "Future events" (or similar) based on standard format, on filter - select "Show Items only when the following is true", select "Begin Date", select "is greater than or equal to", enter "[Today]" in field, click OK to save new view.

Keep in mind that this will also filter out events that have started but have not yet ended. An alternate approach would be to set your custom field to equal the End Time field.

Another SharePoint customization blog offers a way to use a custom yes/no field that calculates if the event has passed.

Thursday, February 14, 2008

SP2007: Search Box CSS

There are many ways to customize the look of the search box using CSS. Heather Solomon's CSS Chart provides a handy reference for these settings and others. There are a few areas it does not address.

One item that you cannot change is the width of the text input box. For some reason the width for this box is hardcoded as a style tag right in the input tag. It is set to 170px. This is unfortunate as a smaller text input field would help my layout.

If you are looking to hide the Advanced Search link, you can do that. Read this post for more information.

Wednesday, February 13, 2008

SP2007: The Advanced Search Link

To have the Advanced Search link appear next to the seach box in the upper right hand corner of your pages you must be using the custom scopes option for the site collection. To do this go to Site Actions, Site Settings, Search Settings and set the custom scopes option following the example. This will make the Advanced Search link appear, and it links to the advanced.aspx page in the Pages library.

If you want to remove the Advanced Search link, but want to keep the custom scopes option, read on...

For reasons of design it is common to want to remove the Advanced Search link and move it to the search results page. Unfortunately there are no settings that allow you to turn this link on and off provided you want to stick with the custom scopes option. Some tutorials will instruct you to replace the search control with your own custom one, but that is complicated and messy. The easiest option is to simply hide the link. This can be done in two ways.

You could add a javascript to your master page to set the inner html of the link to nothing. Create a function and then run that function from the body tag. Something like the following should work:

function hideadvancedsearch() {
document.getElementById('ct100_PlaceHolderSearchArea_ct101_S6AE27B38_AdvSearchLink').innerHTML=" ";
}

While this will hide the link, the spacing will still be off. A cleaner approach is to use your style sheet to set the display property for the table cell to none which will completetly hide that cell of the table.:

.ms-blink
{
display:none;
}

You may also want to set the sbLastcell to none to force the search box to align on the right

.ms-sbLastcell
{
display:none;
}