Friday, January 25, 2008

How to Package a SharePoint Solution (Or How to Rip all of your hair out)...

As I sit here well past 5:00 PM for the second time this week, I wonder what is the best way to package up you custom SharePoint solution to deploy to a production environment. We have tried many ways in the current project we are working on and none of them have proven to be viable methods or consistently deploying our customizations to prepare for the final production deployment next week. The initial project began with creating custom lists, content types, and site columns through the UI. Early on, we realized that we would need some way to move these customizations to the production server and quickly decided that Features and Solutions would be the way to go. We began with using the SharePoint Solution Generator to generate the list definitions. This seemed to work well except we ran into some issues with the generator producing errors and failing.

So onto Plan B. This was to generate the definitions and then put them into Feature files ourselves. This was way too manual and would take longer to package then to create the customizations. So we moved to Plan C. This required the Visual Studio extensions to WSS. This allowed us to package up the Features and deploy them from Visual Studio. We ran into some issues asgain with the extensions not providing all of the functionality that we needed and so I looked for another alternative.

We settled on the CTP 1.1 version of the Visual Studio extensions for WSS. These proved to contain all of the Features that we needed and would deploy reliably over and over again. Or so we thought.

We went to deploy the entire customization solution to prove to ourselves that the entire project would work in production and found some interesting results. When we tried to deploy the solution from the batch file, it died in the middle of activating the Features. This would never work in the production environment. We needed a stable deployment mechanism. So we deleted the web app and started over and this time the solution was deployed but we didn't allow it to activate that features, that way we could manually activate them. This worked reliably but it is quite manual; we had to build in Feature dependencies to make sure that the Features were activated in the same order. Another issue we ran into was that we needed to deploy our base system to two subsites in a single site collection. This did not work by using the VS extensions. The GUIDs that are created are only unique when the Solution is re-deployed from within VS. We needed new GUIDs each time it was deployed from the batch file. When we did the manual activation it worked fine.

The question I pose to all of the other SharePoint developers out there is: What is the best way for deploying customizations to a production environment right now? I realize that the answer will depend on the circumstances but in general what has worked for you?

Labels: , , ,

Monday, December 17, 2007

List Template Types

We have been discussing various parts of features and solutions and how you can use them to efficiently build your SharePoint business solution. One of the most basic things is to create a list template that instances can base themselves on. To begin your list template feature you need to create a ListTemplate element. This element has many attributes that define your list. One of the most important of these is the Type attribute. In the MSDN documentation it states that this is

"Optional Integer. Provides a unique identifier for the template. This identifier must be unique within the feature, but need not be unique across all feature definitions and site definitions. It then lists the built in template types and the type of list that they correspond to:

100 - Custom List
101 - Document Library
102 - Survey
103 - Links List
104 - Announcements List
105 - Contacts List
106 - Events List
107 - Tasks List
108 - Discussion Board
109 - Picture Library
110 - Data Sources
111 - Site Template Gallery
113 - Web Part Gallery
114 - List Template Gallery
115 - XML Form Library
120 - Custom Grid for a list
200 - Meeting Series List
201 - Meeting Agenda List
202 - Meeting Attendees List
204 - Meeting Decisions List
207 - Meeting Objectives List
210 - Meeting Text box
211 - Meeting things to bring list
212 - Meeting Workspace Pages List
300 - Portal sites list
1100 - Issue Tracking
2002 - Personal Document Library
2003 - Private Document Library

It then states that this value corresponds to the Type attribute of the List element.

We have been having some problems with this actually working, though. We built out some lists using the Visual Studio extensions for WSS and we wanted to place some list event receivers on a specific list. Well according to the extensions you should be able to do this by adding the event receivers to the .cs files for that list instance. We tried that and the event receivers were on every custom list. So we poked into the XML for the list instances and found that all of them were using type 100 or (Custom list). So we tried changing them to a different numbers in the 800 range, such as 800, 801, 802, etc. When we tried to deploy the new solution and check the list we received an HRESULT error, which most people know are some of the most unhelpful errors you can get in SharePoint. So we changed the numbers back and then re-deployed and the lists worked fine again.

The documentation says that it needs to be a unique integer across the feature. All of ours were and yet they did not work. If anyone has more insight as to how these list templates really work, feel free to leave a comment explaining them.

Labels: , , ,

Monday, December 10, 2007

Who are you Inherited From?

While working on a new SharePoint project recently, the issue of how best to package the list instances, content types, and site columns to deploy them to a production site cam up. The first time we tried to use Features and Solutions to deploy SharePoint lists, let's just say, was kind of a disaster. We ended up destroying all of the built-in base content types and having to reinstall MOSS on the development server.

This time around I was determined to figure out how to use Features and Solutions to deploy these items. In the next few posts I will describe how I used new tools available to ease this development and the issues I cam across while using Features.

The first problem that I attempted to solve was the inheritance of content types. In our project we had a Request content type that inherits from the base event type. This Request type was then going to be inherited by other content types that I was going to develop and then eventually applied to a list. The first problem I had was the lack of good documentation on the MSDN about content types and how to inherit them. I started to look at some blogs and it seemed that everyone was using a different method and having it work.

I eventually settled on a system that worked. It began by realizing that there are two types of content types - site content types and list content types. Site content types are created at the site level and can be applied to multiple list instances. List content types are an instance of a site content type that is applied to a specific list. This allows you to set a column as hidden or change the order of the columns for a specific list without modifying the site content type.

Once I figured this out the documentation made a little more sense. I ended up creating the Request content type inherit from the base event content type through the "00" + hexadecimal GUID inheritance method. So to inherit from event the content type would look like 0x010200AB1294....continue 32 GUID digits. The ox represents the system type, the 01 the base item type and the 02 the base event type. You then divide your GUID with "00" as a separator. You then append a GUID to make a unique content type identifier.

For the content types that inherit from the Request type you can use the "A0" two hexadecimal digit method for content type inheritance by taking your content type ID for the Request type and appending two hexadecimal digits to it.

This worked well for me in my inheritance project.

To create a list content type for a list instance, I then took my content type ID and using the "00" + hexadecimal GUID method created a unique ID for the list version of the content type.

Another interesting thing with content types and list content types in list instances is that you need to include all of the fields in the list definition as well as the content type in order for the columns to show up in the list instance.

Some of the links that I used for for content types are:

http://msdn2.microsoft.com/en-us/library/aa543822.aspx

http://msdn2.microsoft.com/en-us/library/ms479905.aspx

This second link is the generic link about content types. There is a lot of information here about content types, it just isn't as thorough as it could be.

In the next post I will discuss some new tools to speed development of Features and Solutions.

Labels: , , , ,

Thursday, December 6, 2007

PerformancePoint Server Training

Currently I am taking the PerformancePoint Server - Applications training in preparation for retaking the beta exam for PPS. The training has been very comprehensive and was able to answer some of my questions as to how PerformancePoint and SharePoint are integrated.

As for SharePoint stuff, the next few posts will include more detail about Features and building out Content Types as I am back into the mire that can be Features. I have found some new tools that also help in the creation of Features and Solutions that make the development of them much easier.

Additional upcoming topics include creating a custom field type and rendering it, using Feature Receivers, and some clarification of how content type inheritance really works.

Labels: , , , ,

Wednesday, May 2, 2007

Adding the bulk of Your Site Using Features

To add content to your Sharepoint site using features you need to create a feature.xml file or include the following elements into an existing elements.xml file.

To add content you make use of the Module element.


<Module Name="MainMasterPages"
Path="Masterpages"
Url="_catalogs/masterpage"
RootWebOnly="TRUE"></Module>

In the module element you give it a name attribute that will help you identify different modules. The Path attribute is the location of the files to upload in relation to the elements.xml file. The URL attribute is the URL on the Sharepoint site that you want the files to go. The RootWebOnly attribute is used to say if the file should only be available to the root web. Most of the time you can leave this true.

Within the Module element you place File elements that specify the actual files to upload to Sharepoint.


<File Url="main.master"
Type="GhostableInLibrary">
<Property Name="ContentType" Value="Landscape Master Page" />
<Property Name="Title" Value="Main Master Page" />
<Property Name="MasterPageDescription" Value="Master page for the home page." />
</File>

In the File element you specify the URL that you want the file to have in Sharepoint using the URL attribute. The Type attribute determines if the file will show up in the list or document library. If you set it to GhostableInLibrary then the file will show up. Inside the File elements you can place Property elements to provide additional information about the file. The property elements always consist of a name attribute that represents the name of the data and a value attribute that is the actual data.

In the example above we have a property called ContentType and it has a value that is the type of content that this file is, mainly a master page. The title property allows you to display the title that shows up in lists and when users can change the master page. The MasterPageDescription property allows you to provide a more detailed description of the file for users.

You can follow this same format to upload pretty much any type of content that you have. I have used it to upload master pages, style sheets, and images to the sites and folders that I wanted.

Following are some more links with more detailed information about uploading content:

http://www.andrewconnell.com/blog/archive/2006/12/20/5451.aspx

http://msdn2.microsoft.com/en-us/library/ms441170.aspx

Labels: , , ,

Friday, April 20, 2007

The Filling is the Best Part

In the previous post I showed how to create a list template. In this post we will create an instance of the list and populate it with actual data. This is the real power of a feature for lists. You create the basic Feature.xml and tell it where to look for the Elements.xml file.

In the Elements.xml file you create the following code:


<ListInstance
FeatureId="00BFEA71-DE22-43B2-A848-C05709900100"
Id="1999"
Description="Custom list for the LFI design groups."
TemplateType="100"
Title="LFI Design Groups"
Url="Lists/LFIDesignGroups">
<data>
<rows>
<row>
<field name="Title">35: Chill®</field>
</row>
<row>
<field name="Title">35: Mingle®</field>
</row>
</rows>
</data>
</listinstance>

In the listinstance node you place the feature ID GUID for the feature to base your list instance off of. In the sample code above this is the GUID for the feature of the basic list template. If you do not place a GUID in here, the documentation says that Sharepoint will substitute it with a default one. Don't ever do this as it can screw up the base list templates for the entire server. Always place a GUID in there yourself.

The documentation says that ID is optional but I always include it. It can be pretty much anything, an integer, a string, a GUID. As far as I can tell it is not used by Sharepoint. The only restriction is that it must be unique within the feature.

The description is what you want to show up for the list description. The template type is also grabbed from the list template that you are basing your list on. In this case the list template of 100 is for a custom list.

The title is the title you want to give the list.

The URL is what you want the URL of the list to be.

Inside the listinstance is a data node that contains a rows node and then a row node for each row in the list. Within a row node you place a field node and specify the name of the column that you are going to fill. In this case it is Title. You then place the data inside the node. In this case we are inserting two rows with data of 35: Chill and 35: Mingle. You can place as many nodes as you need to fill your list.

This feature works best if you need to fill a list with static data. You can easily recreate the list later or move the list to a new server such as staging or production.

For more information on list instances:

http://msdn2.microsoft.com/en-us/library/ms476062.aspx

And for more options for a field element:

http://msdn2.microsoft.com/en-us/library/ms437580.aspx

Labels: , , ,

Wednesday, April 18, 2007

A List Template of Your Very Own

To create your own list template using a feature is pretty easy. The only difficult part is trying to understand the documentation on the MSDN about which attributes are required and which are optional. When it comes to my experience with features and list templates, I have found that all of the attributes should be required, otherwise Sharepoint will place something in there for you and in our case this destroyed the out of the box templates on our Sharepoint site.

The first step is to create the Feature.xml file with a name for your feature and the location of the Elements.xml file.

<feature title="Simple List Feature" id="GUID" scope="Web" xmlns="http://schemas.microsoft.com/sharepoint/">
<elementmanifests>
<elementmanifest location="Elements.xml">
</elementmanifests>
</feature>

After that you can create the Elements.xml file and place the ListTemplate node in there.

<elements>
<listtemplate name="SimpleList" displayname="Simple List" type="20" description="This is my simple list." basetype="0" onquicklaunch="FALSE" securitybits="11">
</elements>

The ListTemplate tag is pretty simple. You give it a name and a display name. The display name shows up in the site settings area for list templates. The description field is used to provide more information about your list template. The basetype is the default schema for the lists created from this template. Most times this will be 0. The onquicklaunch allows the list template to show up on the quick launch bar. The security bits allows for read, write, and schema design security.

There are many other fields that you can use in the list template to customize it the way you want. The resource below lists all of these fields.

<edit>
It has been brought to my attention that I forgot to mention the schema.xml file. At the time that this post was originally written, we copied a schema.xml file from an existing list and then modified it. Microsoft recommends this approach as building the schema file from hand is time consuming and very prone to errors. There are also tools out there that will generate schema files from a list that you build using the UI.
</edit>

http://msdn2.microsoft.com/en-us/library/ms462947.aspx

Labels: , , , ,

Friday, April 6, 2007

Back to the Features - Element.xml

In this installment of features we will look at the Element.xml file (or whatever you called it). This is the file that does the actual work in a feature. An example file might look like this:


<?xml version="1.0" encoding="utf-8" ?>
<elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="ViewPhotoPage"
Path="Pages"
Url="Pages"
RootWebOnly="FALSE">
<File Url="viewphoto.aspx"
Type="GhostableInLibrary">
<property name="Title" value="View Photo">
<property name="Description" value="The view photo page.">
</file>
</module>
<Module Name="Images"
Url="PublishingImages"
Path="images"
RootWebOnly="TRUE">
<file url="LFILogo_NoByline.gif" type="GhostableInLibrary">
</module>
</elements></p>

The elements element is required to be in the page. Inside this node you place the module nodes. Each module node does one type of similar action. Modules are used for placing files in the appropriate folders. In this feature we have a module called "ViewPhoto". This module places an aspx file in a directory on the Sharepoint site. The path is the location of the file or files in relation to the Elements.xml file. In this case the files are located in a folder called Pages. The URL attribute tells the feature where in the Sharepoint structure to put the files in this module. In this case it is the top level Pages list. The RootWebOnly attribute says if the files can only be accessed in the root web for the site.

Within the module node you place file nodes that specify the actual file. The URL attribute is the URL you want in the Sharepoint structure for this file. Typ determines if the file shows up in the page libraries. If you use GhostableInLibrary, the page will show up when you browse to the pages library.

Within the file node you can place property nodes that give additional attibutes for the file. In this case we have a title property and a description property. This allows for more descriptive information about the files.

Some things to look out for are the naming conventions in Sharepoint 2007. In some areas a library will be called PublishingImages but can be referenced using just Images. When creating features if you get some of the parts wrong, you can mess up the file system and the default templates for a Sharepoint site. Trust me on this one, I will explain some of the mistakes we have made and the issues we have found in later posts.

For now here are some more reference sites that explain more of the options for the Elements.xml file:

http://msdn2.microsoft.com/en-us/library/ms453137.aspx

http://msdn2.microsoft.com/en-us/library/ms434127.aspx

In the next few posts I will demonstrate how to do various activities using features.

Labels: , ,

Thursday, March 22, 2007

Beware the UI Feature List

I know that I promised to post about features, but I came across an interesting bug in the MOSS feature user interface that needs to be discussed. I will continue on with the feature posts. Today I was recreating our site using the features I have been working on for the last 2 weeks. In the Sharepoint feature UI you get a list of the installed features in either a site collection or a site with buttons next to them to activate or deactivate the feature. Well I was activating the features when I received a message asking me if I wanted to really deactivate this feature. This did not make sense since the feature was not activated yet. I clicked cancel and went back to the UI for the features. I had clicked on the right feature to activate so I refreshed the page and tried it again. This time the feature activated just fine, so I really didn't think nothing of it.

About 10 minutes later I was doing the same process when I received an error that the content type did not exist. This was odd because the feature I was trying to activate did not do anything with a content type. As a side note right here I need to say that I am not the only one working on this install of Sharepoint. There are three of us working on two separate projects and sharing one 12 hive. This was only a problem once before, but that is another story for later. So I poked into the log files and found that there were some errors for JT features so I mentioned to my colleague Joel that he had some errors in the log. He looked into it and found that the error was his feature but that it was being activated on my site. So I looked into the libraries and lists for my site and sure enough there was his list created on my site.

After more poking around we guessed that the UI for the features list is indexed to an internal list of the installed features. What was happening was I would load the page with the list of features and then Joel would install a new feature that was higher up alphabetically in the list and would push the internal list down one. So on the list I was viewing I would go to activate item 3 and in the internal list it would really be item 4. After we suggested this theory to another colleague, he created a simple test by creating three features that began with z and would create an image that corresponded to the feature id. He then loaded the UI page and installed a feature that began with an a. Sure enough if he went to activate the middle z feature it actually activated the first z feature. So we concluded that you need to (if you have multiple people working on the same 12 hive) always refresh the UI page right before activating a feature to make sure you are activating the right feature or use the command line stsadm command to install and activate the features.

Needless to say this provided some entertainment for us this morning.

Labels: , , ,

Thursday, March 15, 2007

Let's start at the beginning.....

To create a feature you first need to define the Feature.xml file. Here is a sample file:


<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
Id="1C552111-5D53-440d-8E6E-50E3B5EB5492"
Title="LFI View Photo Page"
Description="Creates the view photo page."
Scope="Web"
Hidden="false">
<elementmanifests>
<elementmanifest location="Elements.xml">
</elementmanifests>
</feature>

The main areas of this file are the feature node. Here you need to give the feature a unique ID (GUID). You can accomplish this by opening Visual Studio 2005 and clicking on tools. Then select create GUID. While working with feature files, I have noticed that some attributes require the curly braces around the GUID and some don't. You may have to follow the feature documentation to figure this out. The MSDN has good definitions of the elements and the attributes for the elements.

http://msdn2.microsoft.com/en-us/library/ms439657.aspx

The other attributes of the feature element are mostly for your own benefit. The title and description will show up in either the site features or site collection features list. The scope determines where the feature will be installed. For most situations this will be "Web" if you want to deploy the feature to the entire site collection or "Site" if you want it available to the subsites. The hidden attribute determines if the feature will show up in the feature list. If you want to be able to see the feature to activate it, you need to set this to false.

The ElemenetManifests element contains an ElementManifest element that has one attribute, Location. This attribute tells the feature where to look for the rest of the information to activate the feature. In the next post I will begin looking at the Elements.xml file. You can name this file whatever you want, but I find having a convention like naming them all Elements.xml keeps things neat.

Labels: , ,