HOW TO: Programmatically customize site navigation in WSS 3.0 and MOSS 2007

December 26th, 2007 by tbaginski

Note: This is a repost of an article I posted while WSS 3.0 and MOSS 2007 were in the Beta stages.  The article was lost due to a server crash and many people have asked me to repost the article so I updated it with additional information, updates screen shots, and a handy little Windows Forms Application you can use to test these concepts out yourself, or build upon the code base to meet your own needs.  Enjoy!

In the previous version of SharePoint the QuickLaunch menu was controlled via the ONET.XML file and ASPX pages that made up a Site Definition, and making changes to the QuickLaunch menu was a cumbersome task at best.

The new version of SharePoint provides significant improvements to the navigational elements within a SharePoint site as well as the ability to change these elements programmatically! This article describes how to programmatically interact with the navigation elements via the WSS API in order to customize SharePoint site navigation. This article also investigates the security trimming capabilities of the SharePoint UI with respect to programmatically edited navigation links.

The first thing to note is that the objects used to programmatically customize navigation reside in the Microsoft.SharePoint.Navigation namespace. So, you'll need to add a reference to the Microsoft.SharePoint.dll in your Visual Studio projects.

New item: Controlling navigation via the SPWeb object!

The SPWeb object has been enhanced in MOSS 2007 to support the ability to control the navigation of a SharePoint site programmatically! Let's examine how this can be done.

The SPWeb object has a new property named Navigation that returns a SPNavigation object. This object allows developers to programmatically control the navigation of a SharePoint site.

Shared Navigation Settings

One of the new settings you may apply to a site's navigation structure is whether or not the site uses the navigation menus from its parent site.

These examples assume you have created a top level site named test and a sub site named sharednav under the test top level site as well as a sub site named nosharednav under the test top level site. Once these sites have been created their hierarchy and URLs will look like this:

Before we get started, to help set the stage, here is what the navigation looks like in the test site.

Here is an example of how to set a sub site to use the navigation from its parent site.

SPSite sharedNavSite = new SPSite(“http://server/test/sharednav”);

SPWeb sharedNavWeb = sharedNavSite.OpenWeb();

sharedNavWeb.Navigation.UseShared = true;

The navigation for the sharednav site looks like this after the lines of code above have been run to set the property. Notice the breadcrumb trail at the top of the page uses the breadcrumb trail for the test top level site and the horizontal menu bar uses the items from the test top level site as well.

Here is an example of how to set a sub site not to use the navigation from a parent's site.

SPSite noSharedNavSite = new SPSite(“http://server/test/nosharednav”);

SPWeb noSharedNavWeb = noSharedNavSite.OpenWeb();

noSharedNavWeb.Navigation.UseShared = false;

The navigation for the nosharednav site looks like this after the lines of code above have been run to set the property. Notice the breadcrumb trail at the top of the page uses the breadcrumb trail for the nosharednav sub site and the horizontal menu bar uses the items from the nosharednav sub site.

QuickLaunch Menu Items

The QuickLaunch navigation menu may also be accessed programmatically. You can create new menu items in the QuickLaunch navigation menu and remove them. You can also specify if the link is external to the site.

Here is how you add a menu item to the QuickLaunch navigation menu.

These QuickLaunch examples assume you have created a top level site named quicklaunch.

Once this top level site has been created its URL will look like this: http://server/quicklaunch

In this example we will add two links to the QuickLaunch menu for the quicklaunch top level site, one link will be internal and one will be external. The internal link will point to the Links list in the QuickLaunch site. The external link will point to the SharePoint Experts web site.

SPSite quickLaunchSite = new SPSite(“http://server/quicklaunch”);

SPWeb quickLaunchWeb = quickLaunchSite.OpenWeb();

SPNavigationNodeCollection quickLaunchNodes = quickLaunchWeb.Navigation.QuickLaunch;

SPNavigationNode internalMenuItem = new SPNavigationNode(“Links”, “Lists/Links/AllItems.aspx”, false);

quickLaunchNodes.AddAsFirst(internalMenuItem);

SPNavigationNode externalMenuItem = new SPNavigationNode(“SharePoint Experts”, “http://www.SharePointExperts.com”, true);

quickLaunchNodes.AddAsFirst(externalMenuItem);

quickLaunchWeb.Update();

*Note: If you do not call the Update() method on the SPWeb object you are working with, you will need to reset IIS to see your changes.

Here is what the quicklaunch Site Collection looks like after the above code has been executed:

Here is how you remove a menu item from the QuickLaunch navigation menu.

In this example we will remove the external link to the SharePoint Experts web site.

SPSite quickLaunchSite = new SPSite(“http://server/quicklaunch”);

SPWeb quickLaunchWeb = quickLaunchSite.OpenWeb();

SPNavigationNodeCollection quickLaunchNodes = quickLaunchWeb.Navigation.QuickLaunch;

quickLaunchNodes.Delete(quickLaunchNodes([0]));

quickLaunchWeb.Update();

Here is what the quicklaunch Site Collection looks like after the above code has been executed:

Taking the QuickLaunch menu one step further

The QuickLaunch menu is capable of displaying links in a grouped fashion, as you see in the screenshot above. For example, the Lists menu item in the screenshot above has two items under it – the Calendar and Tasks links. Creating your own grouped links can be done programmatically. This is once again a simple process that requires very little code.

Here is how you add grouped menu items to the QuickLaunch navigation menu.

In this example we will create a header link for the group of links and name it Administration. Then we will add two links under the Administration header link. The links will link to the Create and Site Settings pages for the quicklaunch Site Collection.

SPSite quickLaunchSite = new SPSite("http://" + serverTextBox.Text + "/quicklaunch");

SPWeb quickLaunchWeb = quickLaunchSite.OpenWeb();

SPNavigationNodeCollection quickLaunchNodes = quickLaunchWeb.Navigation.QuickLaunch;

SPNavigationNode internalMenuItem = new SPNavigationNode("Administration", "", false);

quickLaunchNodes.AddAsFirst(internalMenuItem);

SPNavigationNode externalSubMenuItem1 = new SPNavigationNode("Site Settings", quickLaunchWeb.Url + "/_layouts/settings.aspx", true);

quickLaunchNodes[0].Children.AddAsFirst(externalSubMenuItem1);

SPNavigationNode externalSubMenuItem2 = new SPNavigationNode("Create", quickLaunchWeb.Url + "/_layouts/create.aspx", true);

quickLaunchNodes[0].Children.AddAsFirst(externalSubMenuItem2);

quickLaunchWeb.Update();

Here is what the quicklaunch Site Collection looks like after the above code has been executed:

*Note: I added the Create and Site Settings links to the QuickLaunch bar to test the security trimmed aspects of the SharePoint UI. I wanted to see if SharePoint would hide these links from users who did not have access to see them because MOSS 2007 hides these links in the out of the box SharePoint UI from users who only have reader access.

I created a user named reader and granted the user read only access to the quicklaunch top level site. When I logged into the quicklaunch top level site with this user the links I just added to the QuickLaunch were available to the reader user! This is an important thing to note, and should be kept in mind when adding links to the QuickLaunch menu!

Here is what the quicklaunch Site Collection looked like when the reader user logged in:

Here is the screen you see when you click one of the links you do not have access to:

Top Navigation Menu Items

The top navigation menu may also be accessed programmatically. You can create new menu items in the top navigation menu navigation menu and remove them. You can also specify if the link is external to the site.

Here is how you add a menu item to the top navigation menu.

This example assumes you have created a top level site named topnavigation.

Once this Site Collection has been created its URLs will look like this: http://server/topnavigation

In this example we will add two links to the top navigation menu for the topnavigation top level site, one link will be internal and one will be external. The internal link will point to the Links list in the topnavigation site. The external link will point to the SharePoint Experts web site.

SPSite topNavigationSite = new SPSite(“http://server/topnavigation”);

SPWeb topNavigationWeb = topNavigationSite.OpenWeb();

SPNavigationNodeCollection topNavigationNodes = topNavigationWeb.Navigation.TopNavigationBar;

SPNavigationNode internalMenuItem = new SPNavigationNode(“Links”, “Lists/Links/AllItems.aspx”, false);

topNavigationNodes.AddAsFirst(internalMenuItem);

SPNavigationNode externalMenuItem = new SPNavigationNode(“SharePoint Experts”, “http://www.SharePointExperts.com”, true);

topNavigationNodes.AddAsFirst(externalMenuItem);

topNavigationWeb.Update();

Here is what the topnavigation top level site looks like after the above code has been executed:

Here is how you delete a menu item from the top navigation menu. In this example we will remove the Links link we just added to the top navigation menu for the topnavigation top level site.

SPSite topNavigationSite = new SPSite(“http://server/topnavigation”);

SPWeb topNavigationWeb = topNavigationSite.OpenWeb();

SPNavigationNodeCollection topNavigationNodes = topNavigationWeb.Navigation.TopNavigationBar;

topNavigationNodes.Delete(topNavigationNodes[0]);

topNavigationWeb.Update();

Here is what the topnavigation top level site looks like after the above code has been executed:

Taking the Top Navigation one step further

The top Navigation menu is capable of displaying dropdown menus that consist of multiple items. Adding additional sub menu items under the topmost item is a simple process and requires very little code.

Here is how you add a sub menu item to a top level menu item in the top navigation menu. In this example we will add a new top level menu item to the top navigation menu that has two sub menu items under it for the topnavigation top level site.

SPSite topNavigationSite = new SPSite(“http://server/topnavigation”);

SPWeb topNavigationWeb = topNavigationSite.OpenWeb();

SPNavigationNodeCollection topNavigationBarNodes =

topNavigationWeb.Navigation.TopNavigationBar;

SPNavigationNode headerMenuItem = new SPNavigationNode("SharePoint Sites", "", false);

topNavigationBarNodes.AddAsFirst(headerMenuItem);

SPNavigationNode externalSubMenuItem1 = new SPNavigationNode("SharePoint Experts", "http://www.SharePointExperts.com", true);

topNavigationBarNodes[0].Children.AddAsFirst(externalSubMenuItem1);

SPNavigationNode externalSubMenuItem2 = new SPNavigationNode("SharePoint University", "http://www.SharePointU.com", true);

topNavigationBarNodes[0].Children.AddAsFirst(externalSubMenuItem2);

topNavigationWeb.Update();

Here is what the topnavigation top level site looks like after the above code has been executed:

*Note: I was curious to see if the Top Navigation menu reacted the same way the QuickLaunch menu bar did regarding the security trimming of the UI. So I created an Administration Header link and two sub links for the Create and Site Settings pages.

I granted the reader user read only access to the topnavigation top level site and when I logged into the topnavigation top level site with this user the links I just added to the Top Navigation menu were available to the reader user! This is an important thing to note, and should be kept in mind when adding links to the Top Navigation menu!

Here is the code I used to add the links:

SPSite topNavigationSite = new SPSite(“http://server/topnavigation”);

SPWeb topNavigationWeb = topNavigationLaunchSite.OpenWeb();

SPNavigationNodeCollection topNavigationBarNodes =

topNavigationWeb.Navigation.TopNavigationBar;

SPNavigationNode headerMenuItem = new SPNavigationNode("Administration", "", false);

topNavigationBarNodes.AddAsFirst(headerMenuItem);

SPNavigationNode externalSubMenuItem1 = new SPNavigationNode("Site Settings", topNavigationWeb.Url + "/_layouts/settings.aspx", true);

topNavigationBarNodes[0].Children.AddAsFirst(externalSubMenuItem1);

SPNavigationNode externalSubMenuItem2 = new SPNavigationNode("Create", topNavigationWeb.Url + "/_layouts/create.aspx", true);

topNavigationBarNodes[0].Children.AddAsFirst(externalSubMenuItem2);

topNavigationWeb.Update();

Here is what the topnavigation top level site looked like when the administrator or the reader user user logged in; the links appear for both users.

I created a handy little Windows Forms Application you can use to test these concepts out yourself, or build upon the code base to meet your own needs. The application is easy to use, just enter the name of your SharePoint server, then click the buttons from top to bottom and follow along with this article. The application looks like this:

I hope this article and the application come in handy for you! Now, it's time to go skiing! :)

SharePoint Connections 2007 Code Samples and Session Materials

November 8th, 2007 by tbaginski

Updated 11/12/2007: The code for my BDC session is now available and linked to below.  Post-conference session materials have been distributed directly to post conference attendees.

I'd like to say thank you to everyone who attended my sessions so at this year's SharePoint Connections Conference.  I met so many smart, easy going people at the conference, and the audiences were a real pleasure to present to.  It's not a conference I will soon forget.

Click here, to download the SharePoint Toolkit application that I used during my SharePoint Object Model and Web Services Kick Start session.

Click here, to download the Site Template Package (stp file) for the SharePoint Site used during Todd Baginski's Using the MOSS SSO Service in Real World Situations session at SharePoint Connections, during November of 2007.  This STP contains all the demos, code and instructions that describe how to implement the solutions in your own environment.

Click here, to download the Site Template Package (stp file) for the SharePoint Site used during Todd Baginski's Getting the Most Out of the Business Data Catalog session at SharePoint Connections, during November of 2007.  This STP contains all the demos, code (including the custom BDC Web Part that displays data from the BDC and the Windows Forms application that displays data from the BDC) and instructions that describe how to implement the solutions in your own environment.

Creating and deploying VSTO Documents inside SharePoint Document Libraries

August 16th, 2007 by tbaginski

This blog has moved.  Click here to open this post on my new blog.

Visual Studio Tools for Office (VSTO) Documents can be deployed to or utilized as templates for a SharePoint Document Library. The process to develop VSTO Documents, deploy them to the SharePoint server, and set the proper security policies on the client machine in order for the documents to run properly can be easily repeated once you understand all the pieces of the puzzle.

I have not been able to find complete documentation for this process on the Internet to date. I have found several web pages that provide pieces of the puzzle, but no comprehensive solution. I discussed this architecture with some Microsoft TS’s and they liked the architecture and approach and gave it two thumbs up.

VSTO Document Basics

To begin, it is important to understand how the VSTO Documents, the SharePoint server, and the target client machines interact.

The following diagram helps illustrate the architecture:

VSTO Documents contain a Deployment Manifest. Inside the Document’s Deployment Manifest, the location of the Assembly the VSTO Document relies upon is stored. This Deployment Manifest can be modified programmatically to point to any location where the Assembly the Document relies upon is stored. By default the Deployment Manifest specifies that the Assembly the document relies upon is stored in the same directory as the Document.

The VSTO Document’s Assembly can be deployed to any file share the user who opens the VSTO document has access to. This location can be on a stand alone file server, or even a file share on the SharePoint server itself. The VSTO Document’s Assembly is a .dll file.

In order for the client machine to properly load and render the VSTO Document and related Assembly, the client machine needs to trust the location from which the VSTO Document is opened and the location from which the Assembly is opened. Creating Security Policies on the client machine that trust the location from which the VSTO Document is opened allows the VSTO Document to properly load and render.

Scenario

The following scenario will be used as an example to demonstrate how to develop, configure and deploy a VSTO Document that will be used as a template for a SharePoint Document Library. Terms that appear in parenthesis are used to represent the various components of the solution and maintain consistency throughout the instructions.

An existing Word Document Template (Sample.dot) utilizes Macros to fill data in the Word Document Template. The majority of the data the users enter into the Macros to fill the document exists within a database, however users are presently keying the information into the Macro prompts manually. The document needs to be migrated to the VSTO format (VSTOSample.dot) in order to take advantage of the data in the database to expedite document creation.

Once the existing Word Document Template has been converted to the VSTO format the VSTO Document Template should be deployed as a template for a given document library (Sample Document Library) on the SharePoint Server (SampleSharePointServer).

Users must be able to open the VSTO Document Template from the Sample Document Library on the SampleSharePointServer and create a new Word Document from the VSTO Document Template. The new Word Document should be able to be saved to the Sample Document Library.

Prerequisites

This solution utilizes the following technologies:

Development environment:

Microsoft Office SharePoint Server 2007 (MOSS 2007)

Visual Studio .NET 2005

Visual Studio Tools for Office 2005 (VSTO 2005)

Client Machine:

Please see the following web page on the MSDN for client machine prerequisites and instructions for installing the prerequisites:

http://msdn2.microsoft.com/en-us/library/2ac08ee2(VS.80).aspx

The Solution

To successfully implement the aforementioned scenario several tasks need to be done.

These tasks are as follows:

  • Convert the existing Word Document Template (Sample.dot) to the VSTO format (VSTOSample.dot).
  • Create a share on a stand alone file server or the SampleSharePointServer server (This example uses a file share on the SampleSharePointServer.)
  • Edit the VSTO Document Deployment Manifest to point to the file share where the VSTO Document’s Assembly is stored.
  • Create a new Sample Document Library Feature in SharePoint for the document library that will utilize the VSTO Document Template. (Please see the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article for instructions.)
  • Install the Sample Document Library Feature on the SampleSharePointServer. (Please see the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article for instructions.)
  • Register the Sample Document Library Feature on the site definition you want the Sample Document Library to be created on when a new SharePoint site is created based on that site definition. (Please see the Adding a Document Library Feature to a Site Definition in WSS V3 / MOSS 2007 article for instructions.)
  • Deploy the VSTOSample.dot file to the SampleSharePointServer.
  • Deploy the VSTOSample.dll to the file share on the SampleSharePointServer.
  • Create Security Policies on the client machine that trust the location the VSTOSample.dot file will be opened from.
  • Test and rejoice!

Step 1: Convert the existing Word Document Template (Sample.dot) to the VSTO format (VSTOSample.dot)

To convert an existing Word Document Template (Sample.dot) to the VSTO format follow these steps:

Open Visual Studio .NET 2005.

Click File | New | Project.

Under Visual C# | Office, select Word Template.

Name the Project VSTOSample.

Click OK.

Select Copy an existing document. (Sample.dot)

Click OK.

At this point VS.NET 2005 converts the existing Sample.dot file to the VSTO format.

Rename Sample.dot in the VS.NET IDE to VSTOSample.dot.

*Note: This can also be done for Word Documents, Excel Workbooks and Excel Templates.

Select Word Document during project creation to convert a .doc file to the VSTO format.

Select Excel Workbook during project creation to convert a .xls file to the VSTO format.

Select Excel Template during project creation to convert a .xlt file to the VSTO format.

*Note: If you are not converting an existing Document follow the same steps as above except select Create a new document instead of Copy an existing document when the dialogue with these options appears during project creation.

Build the project.

Now let’s put some code into the document that will let us know the document was able to access the Assembly and execute code from it after we have deployed the document.

Open the ThisDocument.cs file in the VSTOSample project in the VS.NET 2005 IDE.

Add the following code to the ThisDocument_Startup method.

MessageBox.Show("I'd rather be skiing!");

Run the project. When the project runs the document will appear, then a textbox will appear with the message “I’d rather be skiing!”.

Click OK on the message box and close the document.

Let’s add some more code to the document to demonstrate how a VSTO document can be more efficient at populating documents with information compared to Macros.

First we will add an ActionsPane to the VSTO Document so we have a place to put some simple controls.

In the Visual Studio .NET 2005 IDE right click the VSTOSample project.

Click Add | New Item

Select Actions Pane Control

Name the control ActionsPane.cs

Click Add

Return to the ThisDocument.cs file in the VSTOSample project in the VS.NET 2005 IDE.

Add the following code at the class level:

Private ActionPane actionPane = new ActionPane();

Add the following code to the ThisDocument_Startup method:

this.ActionsPane.Controls.Add(actionPane);

Run the project. When the project runs the document will appear, then a textbox will appear with the message “I’d rather be skiing!” After you click the OK button the Document Actions Pane will appear on the right side of the VSTO Document.

Close the document.

Now let’s add some controls to the Actions Pane.

Open the ActionPane in design mode in VS.NET 2005.

Drag a ComboBox Control and drop it on the ActionsPane designer surface.

Name the ComboBox resortsComboBox

Right click the resortsComboBox control and select Properties

In the Properties Pane scroll to the Items Property and click the … button

Add the following items to the collection of items:

Arapahoe Basin

Wolf Creek Ski Area

Vail

Telluride

Steamboat

Alta

Now, let’s add a control to the document to display our favorite ski resort.

Open the VSTOSample.dot file in the VSTOSample project in design mode.

Add in a BookMark control to the ToolBox in the VS.NET 2005 IDE.

Right click on the ToolBox in the VS.NET 2005 IDE.

Click Choose Items…

Sort by Namespace

Select all the items in the Microsoft.Office.Tools.Word namespace.

Click OK

Type the words “My favorite ski resort is: “ into the document.

Drag a BookMark Control into the document and drop it at the end of the line you just typed.

Name the control favoriteSkiResortBookMark

Finally, let’s add an event handler to the resortsComboBox control to populate the document with the ski resort selected in the resortsComboBox.

Click the button to display the Event Handlers for the resortsComboBox control.

Double click in the SelectedIndexChanged event to create the event handler.

Open the ActionPane.cs file in code view.

Add the following code to the resortsComboBox_SelectedIndexChanged event handler method:

Globals.ThisDocument.favoriteSkiResortBookMark.Text = resortsComboBox.Text;

Run the project. Just like last time, when the project runs the document will appear, then a textbox will appear with the message “I’d rather be skiing!” After you click the OK button the Document Actions Pane will appear on the right side of the VSTO Document. The resortsComboBox control will be populated with the ski resorts you enetered. Selecting an item in the resortsComboBox will populate the document with the name of the selected ski resort in the location where you placed the favoriteSkiResortBookMark control.

Close the VSTOSample project.

*Note: This is a very simple demonstration that illustrates the power of VSTO Documents. Although the data in this example (The Ski Resort Names) does not come from a database, you can easily utilize the power of ADO.NET to return information from a database to populate data bound controls in the Actions Pane. Web Service calls may be used to retrieve the data from back end data sources, so your documents remain loosely coupled to your data layer.

Step 2: Create a share on a stand alone file server or the SampleSharePointServer server (This example uses a file share on the SampleSharePointServer.)

I’m going to assume you know how to do this. For example’s sake I’ll call this share: VSTODocs

Step 3: Edit the VSTO Document Deployment Manifest to point to the file share where the VSTO Document’s Assembly is stored.

I’ve taken care of wrapping the code that does this inside a handy little Windows Form Application that will do this for you. The VSTO Document Deployment Manifest Editor application allows you to easily edit the VSTO Document Deployment Manifest to point to the location where you will deploy the Assembly for the VSTO Document.

Here is a screenshot of the application:

To edit the VSTO Document’s Deployment Manifest simply click the Browse button and browse to the location of the VSTOSample.dot file then select it.

Then type in the UNC path for the file share you created in Step 2. (Make sure you type in the name of the .dll at the end of the path!)

Click the Edit Document Deployment Manifest button and you are done.

There is hardly any code under the hood here that actually edits the Document’s Deployment Manifest. I found the code to do this on the MSDN.

Here is the link to the page on the MSDN that has the code:

http://msdn2.microsoft.com/en-us/library/kck1ffhz(VS.80).aspx

Step 4: Create a new Sample Document Library Feature in SharePoint for the document library that will utilize the VSTO Document Template. (Please see the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article for instructions.)

Step 5: Install the Sample Document Library Feature on the SampleSharePointServer. (Please see the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article for instructions.)

Step 6: Register the Sample Document Library Feature on the site definition you want the Sample Document Library to be created on when a new SharePoint site is created based on that site definition. (Please see the Adding a Document Library Feature to a Site Definition in WSS V3 / MOSS 2007 article for instructions.)

These steps can be skipped if you do not want to make the document a template in a SharePoint Document Library. If you don’t want to make the document a template in a SharePoint Document Library and merely wish to upload the document to a SharePoint Document Library then proceed.

If you want to make the document a template in a SharePoint Document Library by using a SharePoint Feature please see the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article for instructions.

Step 7: Deploy the VSTOSample.dot file to the SampleSharePointServer.

If you chose to perform steps 4, 5 and 6 then this task will already be accomplished.

If you chose not to perform steps 4, 5 and 6 then create a new SharePoint Site.

For examples sake create a site at the following location:

http://SampleSharePointServe/SiteDirectory/VSTOSample

Create a Document Library in the new VSTOSample SharePoint Site you created. Name the Document Library ‘Sample Document Library’. Upload the VSTOSample.dot file to the new Document Library you just created.

Step 8: Deploy the VSTOSample.dll to the file share on the SampleSharePointServer.

Copy the VSTOSample.dll file to the VSTODocs file share on the SampleSharePointServer.

Step 9: Create Security Policies on the client machine that trust the location the VSTOSample.dot file will be opened from.

The following commands are executed on the command line on the client machine.

These commands set up the necessary Security Policies on the client machine that specify the client trusts the location from which the VSTO Document was opened and the location where the Assembly is stored.

%windir%Microsoft.NETFrameworkv2.0.50727caspol -m -ag LocalIntranet_Zone -url "\SampleSharePointServervstodocs*" FullTrust -n "VSTO Documents"

%windir%Microsoft.NETFrameworkv2.0.50727caspol -m -ag LocalIntranet_Zone -url "http://SampleSharePointServer/sitedirectory/*" FullTrust -n "VSTO SharePoint Documents"

You’ll notice in both commands I use a wildcard in the paths. This allows me to trust all the documents and assemblies that are opened from these locations. In a development environment this is a nice approach to take because security is not a big consideration. However, in a production environment I recommend changing these paths to point to the particular VSTO Document and related Assembly.

These commands came from the following MSDN article:

http://msdn2.microsoft.com/en-us/library/ms404837(VS.80).aspx

*Note: To reset Security Policies to their default configuration run the following command at the command line on the client:

%windir%Microsoft.NETFrameworkv2.0.50727caspol -m -rs

Step 10: Test and rejoice!

Open Internet Explorer on the client machine.

Navigate to the VSTOSample SharePoint Site you created.

Look at the bottom toolbar of Internet Explorer.

Check to see the site is in the Local Intranet Zone. (We set the security policies on the Local Intranet Zone, so the paths we set as trusted apply to web sites opened in the Local Intranet Zone.)

Open the Sample Document Library.

Open the VSTOSample.dot file.

The VSTO Word Document Template should open and the “I’d rather be skiing!” Message Box should appear. The resortsComboBox should be populated with data, and selecting a resort will populate the document with the selected ski resort.

If this functionality works you have successfully deployed the VSTO Document to the SharePoint Document Library!

Save the VSTOSample VSTO Word Document Template to the Sample Documents Library by clicking File | Save.

Name the new file VSTOSample – Success.

Return to Internet Explorer and refresh the Sample Document Library page.

You will see you now have a Word Document named VSTOSample – Success.doc in the Sample Document Library.

Nice job! You just made a VSTO document and integrated it with MOSS 2007!

 

This blog has moved.  Click here to comment on this post on my new blog.

Creating a custom Site Definition in WSS V3 / MOSS

August 16th, 2007 by tbaginski

 

This blog has moved.  Click here to open this post on my new blog.

Page moved to http://www.toddbaginski.com/blog/archive/0001/01/01/creating-a-custom-site-definition-in-wss-v3-moss.aspx

Adding a Document Library Feature to a Site Definition in WSS V3 / MOSS 2007

August 16th, 2007 by tbaginski

This is a repost of an article that was lost due to a server crash.

One of the nicest things about Features in the new version of SharePoint is their ability to be added to a Site Definition by default. When you add a Feature to a Site Definition, that Feature is automatically available on a SharePoint site when you create a SharePoint site from the given Site Definition.

This functionality allows developers to build Features and plug them into any Site Definition they choose. In the last version of SharePoint, functionality that can now be delivered in the form of a Feature had to be registered and configured for each Site Definition that utilized the functionality. This is no longer the case because Features encapsulate of all the functionality they deliver.

Plug and play functionality

The relationship between Site Definitions and Features reminds me of the Plug and Play architecture Windows uses to add hardware to your computer.

Windows is a platform which requires a driver to recognize a particular piece of hardware. The driver is responsible for knowing everything about the hardware and it defines how Windows interacts and utilizes the hardware.

SharePoint and Site Definitions are like Windows in this analogy and Features are the hardware. The Feature.xml file acts like a driver that tells SharePoint and Site Definitions everything about the Feature and defines how SharePoint and the Site Definition interact with and utilize the Feature.

Adding Features to Site Definitions

In the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article the SharePoint Feature architecture and the process to create a Feature is explained. Once you have created your own custom Feature you can easily add it to a custom Site Definition. This is perhaps the easiest thing I have found out how to do in the SharePoint V3 so far. Please see the Creating a custom Site Definition in WSS V3 / MOSS 2007 article to learn how to create a custom Site Definition.

This short list of tasks will show you how to add a Feature to a Site Definition.

Step 1: Edit the ONET.XML file for the Site Definition you wish to add the feature to.

Step 2: Reset IIS on the SharePoint server.

Step 3: Create a new SharePoint site based on the Site Definition you added the Feature to.

Short list, eh? See, I told you this was simple!

Step 1: Edit the ONET.XML file for the Site Definition you wish to add the feature to.

This example assumes you have created a custom Site Definition named SAMPLE. Please see the Creating a custom Site Definition in WSS V3 / MOSS 2007 article for instructions.

Open the ONET.XML file for the Site Definition you wish to edit.

The ONET.XML file can be found at the following location on the SharePoint server:

C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATESiteTemplatesSAMPLEXMLONET.XML

Find the section in the ONET.XML file that corresponds to the configuration for the Sample Team Site. The XML Looks like this:

<Configuration ID="0" Name="Default">

<Lists>

<List FeatureId="00BFEA71-E717-4E80-AA17-D0C71B360101" Type="101" Title="$Resources:core,shareddocuments_Title;" Url="$Resources:core,shareddocuments_Folder;" QuickLaunchUrl="$Resources:core,shareddocuments_Folder;/Forms/AllItems.aspx" />

<List FeatureId="00BFEA71-6A49-43FA-B535-D15C05500108" Type="108" Title="$Resources:core,discussions_Title;" Url="$Resources:core,lists_Folder;/$Resources:core,discussions_Folder;" QuickLaunchUrl="$Resources:core,lists_Folder;/$Resources:core,discussions_Folder;/AllItems.aspx" EmailAlias="$Resources:core,discussions_EmailAlias;" />

<List FeatureId="00BFEA71-D1CE-42de-9C63-A44004CE0104" Type="104" Title="$Resources:core,announceList;" Url="$Resources:core,lists_Folder;/$Resources:core,announce_Folder;">

<Data>

<Rows>

<Row>

<Field Name="Title">$Resources:onetid11;</Field>

<Field Name="Body">$Resources:onetid12;</Field>

<Field Name="Expires">&lt;ows:TodayISO/&gt;</Field>

</Row>

</Rows>

</Data>

</List>

<List FeatureId="00BFEA71-2062-426C-90BF-714C59600103" Type="103" Title="$Resources:core,linksList;" Url="$Resources:core,lists_Folder;/$Resources:core,links_Folder;" />

<List FeatureId="00BFEA71-EC85-4903-972D-EBE475780106" Type="106" Title="$Resources:core,calendarList;" Url="$Resources:core,lists_Folder;/$Resources:core,calendar_Folder;" QuickLaunchUrl="$Resources:core,lists_Folder;/$Resources:core,calendar_Folder;/Calendar.aspx" EmailAlias="$Resources:core,calendar_EmailAlias;" />

<List FeatureId="00BFEA71-A83E-497E-9BA0-7A5C597D0107" Type="107" Title="$Resources:core,taskList;" Url="$Resources:core,lists_Folder;/$Resources:core,tasks_Folder;" QuickLaunchUrl="$Resources:core,lists_Folder;/$Resources:core,tasks_Folder;/AllItems.aspx" />

</Lists>

<Modules>

<Module Name="Default" />

</Modules>

<SiteFeatures>

<!– BasicWebParts Feature –>

<Feature ID="00BFEA71-1C5E-4A24-B310-BA51C3EB7A57" />

</SiteFeatures>

<WebFeatures>

<!– TeamCollab Feature –>

<Feature ID="00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5" />

</WebFeatures>

</Configuration>

In the <SiteFeatures> element add the following XML to add your own custom Document Library Feature (Please see the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article for instructions on how to create a custom Document Library Feature.):

<!– Custom Common Document Library Feature –>

<Feature ID="<GUID OF YOUR FEATURE GOES HERE>" />

The <GUID OF YOUR FEATURE GOES HERE> portion of the XML above should be replaced with the GUID you created for your feature. This GUID is found in the ID attribute of the <Feature> element inside the Feature.xml file that corresponds to the custom Document Library Feature you are adding.

Save the ONET.XML file.

Step 2: Reset IIS on the SharePoint server.

On the SharePoint server type iisreset on the command line and wait for IIS to reset.

Step 3: Create a new SharePoint site based on the Site Definition you added the Feature to.

Open Internet Explorer.

Browse to the http://SharePointServerName/SiteDirectory/ site.

Click Create Site

In the Title and URL Name textboxes enter CustomDocLibFeatureSite

In the Template Selection area of the web page click the Custom Site Definitions tab and select the Sample Site template.

Click the Create button.

When the newly created web site appears, click Site Actions and select Site Settings.

Under the Site Administration section, click the Site Features link.

You will see you Custom Document Library Feature in the list!

To activate the Feature, click on the Activate Button next to the Feature in the list.

To create your own Custom Document Library based on this Feature follow these steps:

Click Site Settings

Click Create

Click Custom Document Library

Fill in the required information and create the Custom Document Library.

If you created a custom Document Template in the Document Template dropdown select Custom Document Library for the template.

Click Create.

If you created a custom Document Template clicking the new button on the Custom Document Library toolbar will open the custom Document Template you created.

The beat goes on

Let's take things one step further now. Instead of just adding the Custom Document Library Feature to the Site Definition and making it available, let's create a Custom Document Library list from the Feature when the site is created. This way users will not have to create the Custom Document Library list themselves after the site is created.

The tasks to do this are just as simple as the tasks we just performed. Here is a list of the tasks necessary to make the Custom Document Library Feature list created by default when the site is created from our custom Site Definition.

Step 1: Edit the ONET.XML file for the Site Definition you wish to create the custom Document Library list on.

Step 2: Reset IIS on the SharePoint server.

Step 3: Create a new SharePoint site based on the Site Definition you added the Feature to.

Step 1: Edit the ONET.XML file for the Site Definition you wish to create the custom Document Library list on.

Make sure you are editing the same custom Site Definition that you added the Feature to. If you try to create a list for a Site Definition that does not implement the Feature the list relies upon, an error will occur during site creation indicating the Feature the list relies upon is not available.

This example assumes you have created a custom Site Definition named SAMPLE. Please see the Creating a custom Site Definition in WSS V3 / MOSS 2007 article for instructions.

Open the ONET.XML file for the Site Definition you wish to edit.

The ONET.XML file can be found at the following location on the SharePoint server:

C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATESiteTemplatesSAMPLEXMLONET.XML

In the <Lists> element under the Configuration section we just edited, add the following XML to add your own custom Document Library Feature. (Please see the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article for instructions on how to create a custom Document Library Feature):

<List FeatureId="<GUID OF YOUR FEATURE GOES HERE>"

Type="4000"

Title="Custom Document Library"

Url="Custom Document Library"

QuickLaunchUrl="Custom Document Library/Forms/AllItems.aspx" />

*Note: You can use your own custom Resources file to provide the values for the Title, UTL, and QuickLaunchUrl attributes. Please see the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article for further details. If you have already created a custom Resource file as described in the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article your XML will look like this:

<List FeatureId="<GUID OF YOUR FEATURE GOES HERE>"

Type="4000"

Title="$Resources:customDocumentLibrary,customDocumentLibrary_Title;"

Url="$Resources:customDocumentLibrary,customDocumentLibrary_Folder;"

QuickLaunchUrl="$Resources:customDocumentLibrary,customDocumentLibrary_Folder;/Forms/AllItems.aspx" />

Save the ONET.XML file.

Step 2: Reset IIS on the SharePoint server.

On the SharePoint server type iisreset on the command line and wait for IIS to reset.

Step 3: Create a new SharePoint site based on the Site Definition you added the Feature to.

Open Internet Explorer.

Browse to the http://SharePointServerName/SiteDirectory/ site.

Click Create Site

In the Title and URL Name textboxes enter CustomDocLibFeatureListCreatedSite

In the Template Selection area of the web page click the Custom Site Definitions tab and select the Sample Site template.

Click the Create button.

When the newly create web site appears you will see the Custom Document Library list link on the QuickLaunch navigation menu.

Click the Custom Document Library link to go to the Custom Document Library list.

The Midas touch!

Let's put the finishing touches on our work now. In addition to creating the list by default, let's place a view of the Custom Document Library list on the home page of our custom Site Definition when the site is created.

Once again, this is a very simple task to perform. Here are the steps:

Step 1: Edit the ONET.XML file for the Site Definition you wish to create a default view on the home page of the custom Document Library list on.

Step 2: Reset IIS on the SharePoint server.

Step 3: Create a new SharePoint site based on the Site Definition you added the Feature to.

Step 1: Edit the ONET.XML file for the Site Definition you wish to create a default view on the home page of the custom Document Library list on.

Make sure you are editing the same custom Site Definition that you added the Feature to and created the list on be default. If you try to create a list for a Site Definition that does not implement the Feature the list relies upon an error will occur during site creation indicating the Feature the list relies upon is not available. If you try to create a view of the list and that list has not been automatically created you will get an error during site creation that tells you the list does not exist. (Well, actually the error is `Cannot complete this action')

This example assumes you have created a custom Site Definition named SAMPLE. Please see the Creating a custom Site Definition in WSS V3 / MOSS 2007 article for instructions.

Open the ONET.XML file for the Site Definition you wish to edit.

The ONET.XML file can be found at the following location on the SharePoint server:

C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATESiteTemplatesSAMPLEXMLONET.XML

Find the <Module> in the ONET.XML that is invoked by the Configuration we just edited. The XML looks like this:

<Module Name="Default" Url="" Path="">

<File Url="default.aspx" NavBarHome="True">

<View List="$Resources:core,lists_Folder;/$Resources:core,announce_Folder;" BaseViewID="0" WebPartZoneID="Left" />

<View List="$Resources:core,lists_Folder;/$Resources:core,calendar_Folder;" BaseViewID="0" RecurrenceRowset="TRUE" WebPartZoneID="Left" WebPartOrder="2" />

<AllUsersWebPart WebPartZoneID="Right" WebPartOrder="1"><![CDATA[

<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" xmlns:iwp="http://schemas.microsoft.com/WebPart/v2/Image">

<Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>

<TypeName>Microsoft.SharePoint.WebPartPages.ImageWebPart</TypeName>

<FrameType>None</FrameType>

<Title>$Resources:wp_SiteImage;</Title>

<iwp:ImageLink>/_layouts/images/homepage.gif</iwp:ImageLink>

</WebPart>

]]></AllUsersWebPart>

<View List="$Resources:core,lists_Folder;/$Resources:core,links_Folder;" BaseViewID="0" WebPartZoneID="Right" WebPartOrder="2" />

<NavBarPage Name="$Resources:core,nav_Home;" ID="1002" Position="Start" />

<NavBarPage Name="$Resources:core,nav_Home;" ID="0" Position="Start" />

</File>

</Module>

The <Module> element specifies the resources that Configurations which invoke this mode use. The <File> element specifies files that the Configuration will implement. Inside the <File> element for the default.aspx page add the following XML to create a view of the Custom Document Library list.

<View List="$Resources:core,lists_Folder;/Custom Document Library" BaseViewID="0" WebPartZoneID="Left" WebPartOrder="3" />

*Note: You can use your own custom Resources file to provide the value for the List attribute. Please see the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article for further details. If you have already created a custom Resource file as described in the Creating a Custom Document Library Feature in WSS V3 / MOSS 2007 article your XML will look like this:

<View List="$Resources:core,lists_Folder;/$Resources:customDocumentLibrary,customDocumentLibrary_Folder;" BaseViewID="0" WebPartZoneID="Left" WebPartOrder="3" />

Save the ONET.XML file.

Step 2: Reset IIS on the SharePoint server.

On the SharePoint server type iisreset on the command line and wait for IIS to reset.

Step 3: Create a new SharePoint site based on the Site Definition you added the Feature to.

Open Internet Explorer.

Browse to the http://SharePointServerName/SiteDirectory/ site.

Click Create Site

In the Title and URL Name textboxes enter CustomDocLibViewOnHomePage

In the Template Selection area of the web page click the Custom Site Definitions tab and select the Sample Site template.

Click the Create button.

You will see the Custom Document Library on the home page!

Creating a Custom Document Library Feature in WSS V3 / MOSS 2007

August 16th, 2007 by tbaginski
This blog has moved.  Click here to open this post on my new blog.

Features are a powerful new set of functionality that MOSS 2007 comes with out of the box. Features allow you to deploy functionality inside your MOSS 2007 portal in a granular and loosely coupled fashion. The Document Library that many of the out of the box site definitions come with in MOSS 2007 is implemented as a feature. Building on this out of the box Document Library Feature you can create your own custom Document Library Features as well.

Feature Basics

To begin, let’s take a look at the directories and files that make up a Feature.

Features are stored on the SharePoint Server at the following location:

C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATEFEATURES

Each Feature on the SharePoint Server has its own sub directory that is created in the directory listed above.

Inside each Feature sub directory you will find a file named Feature.xml.

The Feature.xml file holds metadata about the Feature.

Document Library Features

Here is the Feature.xml file that is used to create the DocumentLibrary Feature that comes with MOSS 2007:

<?xml version="1.0" encoding="utf-8" ?>

<!– _lcid="1033" _version="12.0.4017" _dal="1" –>

<!– _LocalBinding –>

<Feature Id="00BFEA71-E717-4E80-AA17-D0C71B360101"

Title="$Resources:core,documentlibraryFeatureTitle;"

Description="$Resources:core,documentlibraryFeatureDesc;"

Version="1.0.0.0"

Scope="Web"

Hidden="TRUE"

DefaultResourceFile="core"

xmlns="http://schemas.microsoft.com/sharepoint/">

<ElementManifests>

<ElementManifest Location="ListTemplatesDocumentLibrary.xml" />

</ElementManifests>

</Feature>

The following metadata about the feature is contained in the Feature element in this XML file.

ID: The GUID that uniquely identifies the Feature

Title: The name of the feature. You will see the name of the Feature displayed on the Site Features web page inside the Site Settings section for a given SharePoint Site.

Description: The description of the feature. You will see the description of the Feature displayed on the Site Features web page inside the Site Settings section for a given SharePoint Site.

Version: The version of the Feature.

Scope: Web or Site are acceptable values here. The scope specifies if the Feature can span an entire site collection, or if the Feature will just be used for an individual sub web.

Hidden: TRUE or FALSE are acceptable values here. This setting specifies if the Feature is visible in the list of Features on the Site Features web page mentioned above. You will notice in the XML below that the DocumentLibrary Feature has its Hidden attribute set to TRUE, this is why you do not see the Document Library in the list of Features on the Site Features web page. Therefore the ability to create a Document Library is not able to be turned off by an end user who has access to the Site Features web page.

DefaultResourceFile: This is the name of the Resource file the feature relies on to provide it with additional configuration information. (More on Resource files later in this document).

You will notice the <ElementManifests> element in the Feature.xml file. This element contains the location of another XML file that contains the different <Elements> this Feature implements.

The <ElementManifest> element specifies that the Feature utilizes a file in the ListTemplates sub directory called DocumentLibrary.xml. The path to sub directories and files is a relative path.

Here is the DocumentLibrary.xml file that holds the <Elements> implemented by the DocumentLibrary Feature:

<?xml version="1.0" encoding="utf-8" ?>

<!– _lcid="1033" _version="12.0.4017" _dal="1" –>

<!– _LocalBinding –>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<ListTemplate Name="doclib"

Type="101"

BaseType="1"

OnQuickLaunch="TRUE"

SecurityBits="11"

Sequence="110"

DisplayName="$Resources:core,doclibList;" Description="$Resources:core,doclibList_Desc;"

Image="/_layouts/images/itdl.gif"

DocumentTemplate="101" />

</Elements>

Notice the <ListTemplate> element? This should look familiar to those who have edited the ONET.XML file in the last version of SharePoint.

The <ListTemplate> element specifies the information needed to make a particular list available on a SharePoint site. The only change to this element you see in this particular example is the addition of the Sequence attribute. As far as I can tell this attribute controls the order of the list on the Create page within a SharePoint site.

Closer inspection reveals some incredibly powerful technology that has been baked into MOSS 2007 – Resource files. This leads us to the topic of Resource files.

Resource Files

The DisplayName and Description attributes have an interesting item in their values. Let’s examine the DisplayName attribute.

The value for this attribute is $Resources:core,docLibList. This value specifies that the doclibList value is read from the core Resource file.

Resource files are stored in the following directory on the SharePoint server:

C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12Resources

Resource files contain key value pairs of information and are used to provide localization capabilities to SharePoint. I believe we will see many developers using Resource files for more than localization in the future because of the power and flexibility they provide.

The $Resources:core part of the value corresponds to the core.en-US.resx resource file.

The docLibList part of the value corresponds to the docLibList <Data> element within the core Resource file.

The XML inside the core resource file that is used to populate the DisplayName and Description attributes of the <ListTemplate> element looks like this:

<Data Name="doclibList">

<Value>Document Library</Value>

</Data>

<Data Name="doclibList_Desc">

<Value>Create a document library when you have a collection of documents or other files that you want to share. Document libraries support features such as folders, versioning, and check out.</Value>

</Data>

At this time I have not been able to find any documentation regarding these files, so I don’t recommend editing the core resource file, instead, make your own.

Another Benefit Of Features

In the last version of SharePoint the ONET.XML file was very big and contained a large amount of information. With the advent of Features the ONET.XML file shrinks because Features are used to componetize the contents of the ONET.XML file. As we have seen here, the <ListeTemplate> element, previously found in the <ListTemplates> element inside the ONET.XML file has been moved into the Document Library Feature. Other out of the box MOSS 2007 lists utilize this same approach.

Creating You Own Document Library Feature

Creating you own custom Document Library Feature is a simple task once you figure out all the pieces of the puzzle. Here is a list of tasks that you will need to do in order to create your own custom Document Library Feature.

Step 1: Create a directory for the Feature.

Step 2: (Optional) Create a custom Resource file.

Step 3: Create the Feature.xml file for the Feature.

Step 4: (Optional) Create the <DocumentTemplate> element inside the ONET.XML file if you are using a custom Document Template for your custom Document Library.

Step 5: Create the ListTemplates sub directory under your new Feature directory.

Step 6: Create the CustomDocumentLibrary.xml file for the Feature.

Step 7: Copy the contents of the DocLib sub directory into your new Feature directory.

Step 8: (Optional) If you plan to use a custom Document Template and you performed Step 4 above – Create a custom Document Template.

Step 9: (Optional) Copy the custom Document Template you created that will server as the default Document Template for your new custom Document Library to the SharePoint server.

Step 10: (Optional) Add the Feature to the site definition you want the feature to be installed on by default when the site is created. (Please see the Adding a Document Library Feature to a Site Definition in WSS V3 / MOSS 2007 article.)

Step 11: Register the Feature with a SharePoint site via the STSADM.EXE command line utility.

Step 12: Reset IIS.

Step 13a: (Assuming you did not do Step 10) Browse to the SharePoint site you registered the feature with. Browse to the Create web page and the custom Document Library will be available in the list of items to create.

Step 13b: (Assuming you did perform Step 10) Create a new SharePoint site with the site definition you edited in Step 10. Browse to the new site to see the custom Document Library already created for you.

*Note: In both cases the custom Document Library Feature will be available on the site.

Step 1: Create a directory for the Feature.

Create a new directory for your Feature in the C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATEFEATURES directory.

This example will use the directory named CustomDocumentLibrary.

Step 2: (Optional) Create a custom Resource file.

Take advantage of the ability to store all your display settings and other items whose values may change frequently in your own Resource file by creating one.

Create a new file named customDocumentLibrary.en-US.resx in the C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12Resources directory.

Inside the file put the following XML:

<?xml version="1.0" encoding="utf-8"?>

<!– _lcid="1033" _version="12.0.4017.1004" _dal="1" –>

<!– _LocalBinding –>

<root>

<Data Name="customDocumentLibrary_Title">

<Value>Custom Document Library</Value>

</Data>

<Data Name="customDocumentLibrary_Folder">

<Value>Custom Document Library</Value>

</Data>

<Data Name="customDocumentLibraryDisplayName">

<Value>Custom Document Library</Value>

</Data>

<Data Name="customDocumentLibraryDescription">

<Value>Create a custom document library when you have a collection of documents or other files that you want to share. Custom document libraries support features such as folders, versioning, and check out.</Value>

</Data>

</root>

Save the file.

Step 3: Create the Feature.xml file for the Feature.

Create a GUID for your feature. You will need to insert this GUID into some of the XML in this document where you see <YOUR GUID HERE>.

You can create a GUID inside VS.NET 2005 or run the following SQL SELECT statement to return a new GUID. SELECT NewID()

Create a file named Feature.xml and place it in the CustomDocumentLibrary directory you just created.

If you performed Step 2 put the following XML in the file:

<?xml version="1.0" encoding="utf-8" ?>

<!– _lcid="1033" _version="12.0.4017" _dal="1" –>

<!– _LocalBinding –>

<Feature Id="<YOUR GUID HERE>"

Title="$Resources:customDocumentLibrary,customDocumentLibrary_Title;"

Description="$Resources:customDocumentLibrary,customDocumentLibraryDescription;"

Version="1.0.0.0"

Scope="Web"

Hidden="FALSE"

DefaultResourceFile="customDocumentLibrary"

xmlns="http://schemas.microsoft.com/sharepoint/">

<ElementManifests>

<ElementManifest Location="ListTemplatesCustomDocumentLibrary.xml" />

</ElementManifests>

</Feature>

If you did not perform Step 2 put the following XML in the file:

<?xml version="1.0" encoding="utf-8" ?>

<!– _lcid="1033" _version="12.0.4017" _dal="1" –>

<!– _LocalBinding –>

<Feature Id="<YOUR GUID HERE>"

Title="Custom Document Library"

Description="Create a custom document library when you have a collection of documents or other files that you want to share. Custom document libraries support features such as folders, versioning, and check out."

Version="1.0.0.0"

Scope="Web"

Hidden="FALSE"

DefaultResourceFile="core"

xmlns="http://schemas.microsoft.com/sharepoint/">

<ElementManifests>

<ElementManifest Location="ListTemplatesCustomDocumentLibrary.xml" />

</ElementManifests>

</Feature>

Remember to replace <YOUR GUID HERE> with the GUID you created!

Save the file.

Step 4: (Optional) Create the <DocumentTemplate> element inside the ONET.XML file if you are using a custom Document Template for your custom Document Library.

Open the ONET.XML file for a custom site definition you have created (Please see the Creating a custom Site Definition in MOSS 2007 article for more details on how to create a custom site definition in MOSS 2007.)

Inside the ONET.XML file create a new <DocumentTemplate> element inside the <DocumentTemplates> element.

If you performed Step 2 use the following XML:

<DocumentTemplate

Path=“SAMPLE”

DisplayName="$Resources:customDocumentLibrary,customDocumentLibraryDisplayName;"

Type="4000"

Default="TRUE"

Description="$Resources:customDocumentLibrary,customDocumentLibraryDescription;">

<DocumentTemplateFiles>

<DocumentTemplateFile Name="doctempwordcustom.dot"

TargetName="Forms/template.doc"

Default="TRUE"/>

</DocumentTemplateFiles>

</DocumentTemplate>

If you did not perform Step 2 use the following XML:

<DocumentTemplate

Path=”SAMPLE”

DisplayName="Custom Document Library"

Type="4000"

Default="TRUE"

Description=" Create a custom document library when you have a collection of documents or other files that you want to share. Custom document libraries support features such as folders, versioning, and check out.">

<DocumentTemplateFiles>

<DocumentTemplateFile Name="doctempwordcustom.dot"

TargetName="Forms/template.doc"

Default="TRUE"/>

</DocumentTemplateFiles>

</DocumentTemplate>

Step 5: Create the ListTemplates sub directory under your new Feature directory.

In the C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATEFEATURESCustomDocumentLibrary directory create a directory named ListTemplates.

Step 6: Create the CustomDocumentLibrary.xml file for the Feature.

Create a file named CustomDocumentLibrary.xml and place it in the ListTemplates directory you just created.

If you performed Step 2 use the following XML:

<?xml version="1.0" encoding="utf-8" ?>

<!– _lcid="1033" _version="12.0.3820" _dal="1" –>

<!– _LocalBinding –>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<ListTemplate

Name="doclib"

Type="4000"

BaseType="1"

OnQuickLaunch="FALSE"

SecurityBits="11"

DisplayName="$Resources:customDocumentLibrary,customDocumentLibraryDisplayName;"

Description="$Resources:customDocumentLibrary,customDocumentLibrary_Folder;"

Image="/_layouts/images/itdl.gif"

DocumentTemplate="4000"/>

</Elements>

If you did not perform Step 2 use the following XML:

<?xml version="1.0" encoding="utf-8" ?>

<!– _lcid="1033" _version="12.0.3820" _dal="1" –>

<!– _LocalBinding –>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<ListTemplate

Name="doclib"

Type="4000"

BaseType="1"

OnQuickLaunch="FALSE"

SecurityBits="11"

DisplayName="Custom Document Library"

Description="Custom Document Library"

Image="/_layouts/images/itdl.gif"

DocumentTemplate="4000"/>

</Elements>

*Note: You can add multiple <ListTemplate> elements here if you wish to create a Feature that deploys multiple document libraries at a time.

Step 7: Copy the contents of the DocLib sub directory into your new Feature directory.

In the C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATEFEATURESCustomDocumentLibrary directory create a directory named DocLib.

Copy the contents of the C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATEFEATURESDocumentLibraryDocLib directory to the new DocLib directory you just created.

Step 8: (Optional) If you plan to use a custom Document Template and you performed Step 4 above, create a custom Document Template.

Open Microsoft Word.

Type in “Sample document template” into the document.

Click File | Save As

In the dropdown list that says Save as type: select Document Template (.dot)

Name the file custom.dot

Click the Save button.

Step 9: (Optional) Copy the custom Word Document Template you create that will server as the default Document Template for your new custom Document Library to the SharePoint server.

Copy the custom.dot file to the following directory on the SharePoint server:

C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATE1033<NAME OF CUSTOME SITE DEFINITION>DOCTEMPWORD

Step 10: (Optional) Add the Feature to the site definition you want the feature to be installed on by default when the site is created. (Please see the Adding a Document Library Feature to a Site Definition in WSS V3 / MOSS 2007 article.)

Step 11: Register the Feature with a SharePoint site via the STSADM.EXE command line utility.

On the SharePoint server type the following command on the command line to change to the directory stsadm.exe resides in:

cd “C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12BIN”

Then type the following command to install the feature on the SharePoint server:

stsadm -o installfeature -filename "CustomDocumentLibraryfeature.xml"

This example assumes you have created a SharePoint site at the following URL:

http://SharePointServerName/SiteDirectory/CustDocLib

To activate the feature on the SharePoint site mentioned above site use the following command:

stsadm –o activatefeature –filename “CustomDocumentLibraryfeature.xml” –url “http://SharePointServerName/SiteDirectory/CustDocLib”

*Note: You can also uninstall and deactivate features using the stsadm utility.

Uninstall command line: stsadm -o uninstallfeature -filename "CustomDocumentLibraryfeature.xml"

Deactivate command line: stsadm –o deactivatefeature –filename “CustomDocumentLibraryfeature.xml” –url “http://SharePointServerName/SiteDirectory/CustDocLib”

Step 12: Reset IIS.

On the SharePoint server type iisreset on the command line and wait for IIS to reset.

Step 13a: (Assuming you did not do Step 10) Browse to the SharePoint site you registered the feature with. Browse to the Create web page and the custom Document Library will be available in the list of items to create.

Open Internet Explorer.

Browse to the http://SharePointServerName/SiteDirectory/CustDocLib site.

Click Site Settings

Click Create

Click Custom Document Library

Fill in the required information and to the Custom Document Library.

(If you created a custom Document Template) In the Document Template dropdown select Custom Document Library for the template.

Click Create.

If you created a custom Document Template clicking the new button on the Custom Document Library toolbar will open the custom Document Template you created.

Step 13b: (Assuming you did perform Step 10) Create a new SharePoint site with the site definition you edited in Step 10. Browse to the new site to see the custom Document Library already created for you.

Open Internet Explorer.

Create a new SharePoint site with the custom site definition you edited.

You will see the Custom Document Library already created for you and listed in the QuickLaunch Navigation on the left hand side of the site.

If you created a custom Document Template clicking the new button on the Custom Document Library toolbar will open the custom Document Template you created.

This blog has moved.  Click here to comment on this post on my new blog.

Connected Page Viewer Web Part

August 16th, 2007 by tbaginski

This is a repost of an article on my blog that was lost during a server failure.  Historically, this has been one of the most popular articles on my blog, so I dug up the code and put it back online.

The code you will find below is for a Connected Page Viewer Web Part for WSS V2 and SPS 2003.  The Connected Page Viewer Web Part consumes a URL from another Web Part that provides URLs.  This Web Part WORKS GREAT in WSS V3 and MOSS 2007 as well.

Enjoy!

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Security;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.WebPartPages.Communication;
using System.Text;
using System.IO;

namespace Custom.SharePoint.WebParts
{
/// <summary>
/// This Web Part displays the contents of a URL that is passed in from a provider web part.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:ConsumerPageViewer runat=server></{0}:ConsumerPageViewer>"),
XmlRoot(Namespace="Custom.SharePoint.WebParts")]
public class ConsumerPageViewer : WebPart , ICellConsumer
{
#region Properties

/// <summary>
/// The URL to display in the IFRAME
/// </summary>
private string pageUrl = string.Empty;
/// <summary>
/// The property that exposes the pageUrl variable
/// </summary>
[Browsable(true),
Category("Customization"),
DefaultValue(""),
WebPartStorage(Storage.Personal),
FriendlyName("Page Url"),
Description("Default page URL such as Posted in Uncategorized | No Comments »

Which WSS 3.0 / MOSS 2007 site Template is right for me?

June 29th, 2007 by tbaginski

MOSS 2007 ships with many predefined Templates you may use to create Site Collections and sub sites. Sometimes the out of the box site Templates will meet the needs of your project. Other times, the out of the box site Templates may need to be enhanced.

Knowing which site Template has the functionality you need to deploy, or use as a baseline for a custom Site Definition, is one of the key decisions you make when architecting a SharePoint deployment. This being said, it is important to understand the functionality the Templates WSS and MOSS come with out of the box, and what they look like.

This post will outline what functionality the site Templates WSS and MOSS come with out of the box, what they look like, and document several useful peices of information developers will find handy when working with the out of the box SharePoint site Templates.

MOSS offers some guidance by providing descriptions and preview images for each out of the box template. However, not all of these descriptions list which resources the site comes provisioned with, and the preview images are no help at all. See the image below, I think you will agree.

    Click on thumbnail for full size image.

To better understand the inventory of out of the box site Templates, I created a Site Collection based on each out of the box site Template. After creating 23 different Site Collections, I realized it would be hard to remember what each one looked like. So, I decided to take some screenshots and document the site Templates.

Below you will find tables corresponding to the different categories the site Templates reside in. The tables list the site Template names and descriptions for each category. As I mentioned before, you will see these descriptions are a good starting point, but do not describe the various lists that are provisioned with each site.

Collaboration Category Descriptions

    Click on thumbnail for full size image.

Meetings Category Descriptions

    Click on thumbnail for full size image.

Enterprise Category Descriptions

    Click on thumbnail for full size image.

Publishing Category Descriptions

    Click on thumbnail for full size image.

Preview Images

If you care to see what all of the preview images look like, you can find them in the following directory on your SharePoint server:

C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATELAYOUTS1033IMAGES

The file names for the preview images corresponding to each site Template are listed in the tables below.

A More Detailed Look

If you care to see what each of the home pages for the site Templates looks like, you can download them from this file. These images should give you a good understanding of the different Lists and layouts that come with each out of the box Template.  This should save you a lot of time creating each type of site Template on your own machine!

Information developers will want to keep handy when enhancing or creating new custom Site Templates and Site Definitions.

The next table lists the WEBTEMP XML fragment file each site Template and Configuration is stored in, the file name of the preview image, and the concatenated Template and Configuration string you need when making sites with this site Template programmatically. If you wish to change the out of the box preview images I recommend backup up the existing preview images, then replacing them with your new preview images that have the same file names. Feel free to use the images I created from screenshots of each site Template's out of the box home page to do so. You can download them here.

* You may have to perform this process again after a service pack is applied in the future. It is not supported to edit the various WEBTEMP files that come out of the box, so that is why I recommend this approach.

    Click on thumbnail for full size image.

Buried Treasure: Crouching Tiger- Hidden Templates!

Many of the site Templates listed in the following table are left over from the last version of SharePoint and are marked obsolete. However some of them may be created programmatically. I included the list of all the hidden site Templates here for your reference.

    Click on thumbnail for full size image.

Leverage this information to create SharePoint sites programmatically

The concatenated Template and Configuration string is used when creating sites programmatically. See the below code sample for an example, pay attention to the text in orange, to see where the concatenate string is used.

//Create a new SPSite object corresponding to your top level site

SPSite newSite = new SPSite(“http://moss/site”);

//Create a new SPWeb object from the newSite object

SPWeb newWeb = newSite.OpenWeb();

//Return the collection of sub sites

SPWebCollection subSites = newWeb.Webs;

//Create a new sub site by adding it to the sub site collection

//The new site will have the following metadata:

//Full URL once created: http://moss/newsite

//Name: New Site

//Description: This is the description for my new site.

//Local ID set to 1033 – English

//Site Template: Team Site

//Use Unique Permissions: True

SPWeb newSubWeb = subSites.Add(“newsite”, “New Site”, “This is the description for my new site.”, 1033, “STS#0“, true, false);

Important planning information related to the out of the box site Templates!

This chart shows the available site Templates one may create sub sites with, for a given parent site Template. Make sure you pick site Templates that will allow you to create the types of sub sites your functionality requirements dictate.

    Click on thumbnail for full size image.

I hope this post comes in handy for you and saves you the time I spent digging through the SharePoint file system and creating dozens of SharePoint sites to find the information. All the information in this post comes from the RTM version of MOSS 2007 Enterprise.

SharePoint Development Bootcamp – 2nd Quarter Public Dates Announced

May 22nd, 2007 by tbaginski

Earlier this week we announced the dates for our next public Bootcamps.  I've been busy adding all sorts of great content to my SharePoint Development Bootcamp and I'm really looking forward to teaching it in Vegas July 30 - August 3.

I'm especially excited this time because Heather Solomon and Matt Passanante will also be teaching their SharePoint Branding Bootcamp and SharePoint Administration and Planning Bootcamp, respectively.  Dustin Miller will be on site all week long supporting the different classes, and cracking them up with his endless supply of jokes.

On the final day we will merge all the instructors and classes together for a 'Stump The Instructors' session which should be a very fun afternoon of Q&A.

Many people have already signed up for the Bootcamp experience, and I'm looking forward to meeting all of you!  Tickets are going faster than ever with the ever-growing popularity of SharePoint, so if you would like to attend, sign up soon.

SharePoint Feature Manager Update 1.0.0.2

May 22nd, 2007 by tbaginski

 

Today I updated the SharePoint Feature Manager to fix an interesting bug I found.

On my development VPC that was upgraded from B2TR to RTM the path to the Features directory was:

C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATEFEATURES

On my development VPC that has a fresh install of RTM the path to the Features directory is:

C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12TEMPLATEFEATURES

The change in capitalization of the Web Server Extensions directory, highlighted in bold above, caused a path replacement inside the SharePoint Feature Manager to fail on the fresh install of the RTM build.  I've fixed the bug and the application will now work properly on SharePoint installations that were not upgraded from B2TR, as well as SharePoint installations that were upgraded from B2TR to RTM. 

You can download it here: /files/folders/tbaginski/entry2449.aspx