Thursday, December 8, 2011

Creating a ListDefinition schema.xml from a List Template (SharePoint 2007)

Have a read of this great article:
Create the structure as per the article above.
  • Create a list in SharePoint and customise it.
  • Save it as a List template.
  • Save the list template file from the list gallery to your local machine.
  • Rename the file extension from STP to CAB.
  • Open up the file and extract the manifest.xml
  • Open up the manifest.xml
All you're concerned with in this file are the following nodes:
  • ListTemplate\UserLists\List\Views
  • ListTemplate\UserLists\List\Fields
Using the original schema.xml file as a template you can copy chunks of XML from the manifest.xml into/over relevant sections.
I've also found it useful to remove all the "ContentType" nodes from the schema.xml file. Otherwise when you go to create a new item or edit an item your custom fields won't show up. You can leave the ContentTypes node just clear out it's contents.

I hope this helps you avoid manually typing out some XML and further associated headaches.
As a quick reference the custom list schema.xml file can be found here:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\CustomList\CustList\schema.xml

Sunday, October 30, 2011

SharePoint: CAML get all calendar items from including recurring items

Situation:
I want to get all calendar items from today onwards including any recurring event items.

Problem:
CAML and SharePoint can be a pain.

Solution:
SPQuery query = new SPQuery();
string queryString =
@"
    <Where>
     <DateRangesOverlap>
      <FieldRef Name=""EventDate""/>
      <FieldRef Name=""EndDate""/>
      <FieldRef Name=""RecurrenceID""/>
      <Value IncludeTimeValue=""TRUE"" Type=""DateTime"">
       <Now/>
      </Value>
     </DateRangesOverlap>
    </Where>
    <OrderBy>          
 <FieldRef Name=""EventDate"" Ascending=""TRUE""/>      
    </OrderBy>
";
query.Query = queryString;
query.ExpandRecurrence = true;

Note:
You should add a query.RowLimit so you don't get too many items back. But that's up to you.

Sunday, October 23, 2011

SharePoint Site Template custom Navigation

Ok this should be simple. It should be straight forward. I should have known better.

Scenario: I'm building a SharePoint 2010 web template.
What I want to do: I want to display two links in the top nav (Home & Shared Documents). I want this navigation to be available as soon as the Site collection is created. There's an obvious place in the onet.xml file to place this. But this area is poorly documented. I had to do a bit of trial and error to achieve what I wanted.

This is the solution to my problem but I have spent way too much time to achieve something so simple.

<NavBars>
 <NavBar Name="$Resources:core,nav_Home;" Separator="&amp;nbsp;&amp;nbsp;&amp;nbsp;" Body="&lt;a ID='onettopnavbar#LABEL_ID#' href='#URL#' accesskey='J'&gt;#LABEL#&lt;/a&gt;" ID="1002" />
 <NavBar Name="SharePoint Top Navbar" ID="1002">
  <NavBarLink Name="Shared Documents" Url="Shared%20Documents/">
  </NavBarLink>
 </NavBar>
</NavBars>

"SharePoint Top Navbar" is the top navigation nav bar. If you want to add links to the top navigation you need to add them in this node.

Sunday, October 9, 2011

Restoring a site collection and getting a "different version of Microsoft SharePoint Foundation" error

Scenario:
Restoring a site collection backup between 2 development environments. I'm using the following Powershell command:
Restore-SPSite -Identity http://spdev/sites/ctmh -Path c:\fpbackups\ctmh.bak
Where spdev is the name of my SharePoint Dev server.
ctmh.bak is the backup file.

Symptom:
Restore-SPSite : Your backup is from a different version of Microsoft SharePoint Foundation and cannot be restored to a server running the current version. The backup file should be restored to a server with version '4.1.9.0' or later.

Steps to get it working:
It seemed pretty straight forward although the version '4.1.9.0' seemed a little strange.
First step is to compare both environment's SharePoint version:
  1. SharePoint 2010 Central Administration
  2. Upgrade and Migration
  3. Check product and patch installation status
I looked up the version number on my favourite search provider and got the appropriate updates. Pretty straight forward really.

I forgot to run the "SharePoint 2010 Products Configuration Wizard" initially and the restore didn't work. So if the SharePoint versions are the same between environments it might be worth while running the wizard to check that the patches have been applied.

Friday, April 15, 2011

Hiding a Flash component in a page

I was scratching my head over this one for a while. I tried putting a Flash component in a DIV and then set the Display: none

This usually works. But not for Flash.

Long story short. The solution I found set is to set either height: 0px or width: 0px.

You may also need to set the overflow: hidden

<div style:"height: 0px; overflow: hidden>Flash thingy goes here</div>

Then when I want to display it I set the width/height via client side script.

Friday, April 8, 2011

SharePoint: Delete list via STSADM

stsadm.exe -o forcedeletelist -url http://exampleIntranet/Lists/AListToDelete

I found this very useful today.

I was having issues reaching: _layouts/sitemanager.aspx
I kept getting: Object reference not set to an instance of an object.

After a bit of poking around I found that I couldn't get to one of my lists (I'm messing with List definitions and instances). The STSADM command above saved my behind.

Thursday, April 7, 2011

SharePoint 2010: customErrors in Web.Config

Ok I've been trying to ignore this one for a while but it's got to me. I had to figure out why changing <customErrors mode="Off" /> in the usual web.config in your Web App didn't do anything.

So I did a search of the file system and found this file:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\web.config

Yep that's right. You have to change the customErrors setting in this file as well.

Joys of SharePoint...

Wednesday, March 23, 2011

SharePoint 2010: SP.UI.ModalDialog.showModalDialog not ready

I'm building a custom component which displays "ads". It needs to check a list to see if the current user has seen the ad. If they haven't then display a SharePoint 2010 modal dialog.

What I did (Javascript):
_spBodyOnLoadFunctionNames.push("OpenMyAd");

What was needed:
ExecuteOrDelayUntilScriptLoaded(OpenMyAd, "sp.ui.dialog.js");

Which does exactly what it says on the tin... It waits until the script is loaded and then executes what I told it to.

Credit goes to Sing Chan and his post.