in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Todd Baginski's SharePoint 2003 and MOSS 2007 Blog

August 2007 - Posts

  • Creating and deploying VSTO Documents inside SharePoint Document Libraries

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

    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.NET\Framework\v2.0.50727\caspol -m -ag LocalIntranet_Zone -url "\\SampleSharePointServer\vstodocs\*" FullTrust -n "VSTO Documents"

    %windir%\Microsoft.NET\Framework\v2.0.50727\caspol -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.NET\Framework\v2.0.50727\caspol -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!

  • Creating a custom Site Definition in WSS V3 / MOSS

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

    The new version of SharePoint brings some changes to the way Site Definitions are created and deployed to a SharePoint server. Additionally, the way Site Definitions are now architected has changed with the advent of Features. Although FrontPage 2003 has been significantly enhanced to become the Office SharePoint Designer, Features allow for more flexible deployments of functionality within SharePoint, and Master Pages allow us to change the look and feel of many sites inside SharePoint with a single click of a button - custom Site Definitions can still be leveraged to provide outstanding enterprise wide flexibility and ease of maintenance for SharePoint sites.

    Site Definitions are a complex and large topic that we will not delve into in an in depth manner right now. The purpose of this document is to describe how to create a custom Site Definition in order to set the stage for the other documentation.

    Site Definition basics

    Site Definitions are located in the following folder on the SharePoint server:

    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates

    Each Site Definition has its own sub directory under this folder.

    Inside each Site Definition sub directory the aspx pages for the various web pages and lists that make up the Site Definition are stored. The ONET.XML file that specifies the various configurations and modules the Site Definition is made up of is stored inside the XML subdirectory inside each Site Definition sub directory.

    *Note: I think it is interesting that the SDK refers to Site Templates as the .stp files that are generated when you save a site as a template from the web UI, and the SDK refers to file based site templates as Site Definitions – yet this directory is named SiteTemplates.

    Site Definitions are registered with SharePoint and made available via the WEBTEMP<NAME OF SITE DEFINITION>.XML file.

    These files are located in the following folder on the SharePoint server:

    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\XML

    Creating a custom Site Definition in MOSS 2007

    The following tasks are all you need to do to create a custom Site Definition in MOSS 2007.

    Step 1: Clone an existing Site Definition.

    Step 2: Create the WEBTEMP XML fragment file to register the Site Definition with SharePoint.

    Step 3: Reset IIS

    Step 4: Create a site based on the custom Site Definition.

    Step 1: Clone an existing Site Definition.

    Navigate to the following directory on the SharePoint server in Windows Explorer:

    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates

    Copy the STS directory and paste it back into the same directory.

    Rename the Copy of STS directory to SAMPLE

    Navigate to the following directory on the SharePoint server in Windows Explorer:

    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033

    Copy the STS directory and paste it back into the same directory.

    Rename the Copy of STS directory to SAMPLE

    Step 2: Create the WEBTEMP XML fragment file to register the Site Definition with SharePoint.

    Create a file called WEBTEMPSAMPLE.XML in the following directory:

    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\XML

    Put the following XML into the WEBTEMPSAMPLE.XML file:

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

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

    <!-- _LocalBinding -->

    <Templates xmlns:ows="Microsoft SharePoint">

    <Template Name="SAMPLE" ID="10001">

    <Configuration ID="0" Title="Sample Site" Hidden="FALSE" ImageUrl="/_layouts/images/stsprev.png" Description="This sample template creates a site for teams to create, organize, and share information quickly and easily. It includes a Document Library, and basic lists such as Announcements, Calendar, Contacts, and Quick Links." DisplayCategory="Custom Site Definitions" > </Configuration>

    <Configuration ID="1" Title="Sample Blank Site" Hidden="FALSE" ImageUrl="/_layouts/images/stsprev.png" Description="This sample template creates a Windows SharePoint Services-enabled Web site with a blank home page. You can use a Windows SharePoint Services-compatible Web page editor to add interactive lists or any other Windows SharePoint Services features." DisplayCategory="Custom Site Definitions" > </Configuration>

    <Configuration ID="2" Title="Sample Document Workspace" Hidden="FALSE" ImageUrl="/_layouts/images/dwsprev.png" Description="This sample template creates a site for colleagues to work together on documents. It provides a document library for storing the primary document and supporting files, a Task list for assigning to-do items, and a Links list for resources related to the document." DisplayCategory="Custom Site Definitions" > </Configuration>

    </Template>

    </Templates>

    *Note: The DisplayCategory attribute of the <Configuration> element dictates which tab the configuration will appear on in the Template Selection section of the create site web page. You can create your own tabs by putting your own values in this attribute (like we have done here).

    Save the file.

    Step 3: Reset IIS

    Open a command prompt on the SharePoint server.

    Type in the command: iisreset

    Wait for IIS to reset

    Step 4: Create a site based on the custom Site Definition.

    Open Internet Explorer

    Navigate to the Sites Directory in your SharePoint portal (http://SharePointServerName/SiteDirectory)

    Click the Create Site Link

    Fill out the information on the form.

    Notice at the bottom of the page in the Template Selection section the new Custom Site Definitions tab.

    Click this tab and select one of the available configurations.

    Click the Create button.

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

    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 Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\SAMPLE\XML\ONET.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 Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\SAMPLE\XML\ONET.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 Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\SAMPLE\XML\ONET.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

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

    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 Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES

    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="ListTemplates\DocumentLibrary.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 Files\Common Files\Microsoft Shared\web server extensions\12\Resources

    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 Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES 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 Files\Common Files\Microsoft Shared\web server extensions\12\Resources 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="ListTemplates\CustomDocumentLibrary.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="ListTemplates\CustomDocumentLibrary.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="doctemp\word\custom.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="doctemp\word\custom.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 Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\CustomDocumentLibrary 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 Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\CustomDocumentLibrary directory create a directory named DocLib.

    Copy the contents of the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\DocumentLibrary\DocLib 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 Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\<NAME OF CUSTOME SITE DEFINITION>\DOCTEMP\WORD

    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 Files\Common Files\Microsoft Shared\web server extensions\12\BIN”

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

    stsadm -o installfeature -filename "CustomDocumentLibrary\feature.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 “CustomDocumentLibrary\feature.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 "CustomDocumentLibrary\feature.xml"

    Deactivate command line: stsadm –o deactivatefeature –filename “CustomDocumentLibrary\feature.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.

  • Connected Page Viewer Web Part

    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 http://www.sharepointexperts.com")]
    public string PageUrl
    {
    get {return pageUrl;}
    set {pageUrl = value;}
    }

    /// <summary>
    /// Variable to toggle if the URL of the content in the web part is displayed.
    /// </summary>
    private bool showPageUrl = false;
    /// <summary>
    /// The property that exposes the showPageUrl variable
    /// </summary>
    [Browsable(true),
    Category("Customization"),
    DefaultValue(false),
    WebPartStorage(Storage.Shared),
    FriendlyName("Show Page Url"),
    Description("Specifies if the URL of the content in the web part is displayed.")]
    public bool ShowPageUrl
    {
    get {return showPageUrl;}
    set {showPageUrl = value;}
    }
    #endregion
    // Event required by ICellConsumer
    public event CellConsumerInitEventHandler CellConsumerInit;

    // Keep a count of ICellConsumer connections.
    private int cellConnectedCount = 0;

    // Cell information
    private string cellName = "Cell Data"

    /// <summary>
    /// Register interfaces.
    /// </summary>
    public override void EnsureInterfaces()
    {
    try
    {
    // Register the ICellConsumer interface.
    RegisterInterface("CellConsumer_WPQ_",
    "ICellConsumer",
    WebPart.UnlimitedConnections,
    ConnectionRunAt.Server,
    this,
    "CellConsumer_WPQ_",
    "Consumes a cell from",
    "Consumes a cell of data");
    }
    catch(SecurityException)
    {
    }
    }

    /// <summary>
    /// This method is called by the framework to determine whether a part
    /// can be run on the client or server based on the current
    /// configuration.
    /// </summary>
    public override ConnectionRunAt CanRunAt()
    {
    return ConnectionRunAt.Server;
    }

    /// <summary>
    /// Notification to the Web Part that it has been connected
    /// </summary>
    /// <param name="interfaceName">Unique name of the interface that is being connected</param>
    /// <param name="connectedPart">Reference to the other Web Part that is being connected to</param>
    /// <param name="connectedInterfaceName">Unique name of the interface on the other Web Part</param>
    /// <param name="runAt">Where the interface should execute</param>
    public override void PartCommunicationConnect(string interfaceName,
    WebPart connectedPart,
    string connectedInterfaceName,
    ConnectionRunAt runAt)
    {
    EnsureChildControls();
    if (interfaceName == "CellConsumer_WPQ_")
    {
    cellConnectedCount++;
    }
    }

    /// <summary>
    /// In this method, a part should fire any connection init events.
    /// </summary>
    public override void PartCommunicationInit()
    {
    if(cellConnectedCount > 0)
    {
    if (CellConsumerInit != null)
    {
    CellConsumerInitEventArgs cellConsumerInitArgs = new CellConsumerInitEventArgs();
    cellConsumerInitArgs.FieldName = cellName;
    CellConsumerInit(this, cellConsumerInitArgs);
    }
    }
    }

    /// <summary>
    /// This method is called by the Authoring environment for all
    /// the initial data required for creating a connection.
    /// </summary>
    /// <param name="interfacename">Name of interface that the framework is
    /// requesting information on</param>
    /// <returns>An EventArgs object such as CellProviderInitArgs</returns>
    public override InitEventArgs GetInitEventArgs(string interfaceName)
    {
    if (interfaceName == "CellConsumer_WPQ_")
    {
    EnsureChildControls();
    CellConsumerInitEventArgs cellConsumerInitArgs = new CellConsumerInitEventArgs();
    cellConsumerInitArgs.FieldName = cellName;
    return(cellConsumerInitArgs);
    }
    else
    {
    return(null);
    }
    }

    /// <summary>
    /// The CellProviderInit event handler
    /// The Provider part will fire this event during its PartCommunicationInit phase.
    /// </summary>
    /// <param name="sender">Provider Web Part</param>
    /// <param name="cellProviderInitArgs">The args passed by the Provider</param>
    public void CellProviderInit(object sender, CellProviderInitEventArgs cellProviderInitArgs)
    {
    // This is where the Consumer part can identify what type of "Cell" the Provider
    // will be sending.
    }

    /// <summary>
    /// The CellReady event handler
    /// The Provider part will fire this event during its PartCommunicationMain phase.
    /// </summary>
    /// <param name="sender">Provider Web Part</param>
    /// <param name="cellReadyArgs">The args passed by the Provider</param>
    public void CellReady(object sender, CellReadyEventArgs cellReadyArgs)
    {
    if(cellReadyArgs.Cell != null)
    {
    pageUrl = cellReadyArgs.Cell.ToString();
    }
    }

    /// <summary>
    /// Render this Web Part control to the output parameter specified.
    /// </summary>
    /// <param name="output"> The HTML writer to write out to </param>
    protected override void Render(HtmlTextWriter output)
    {
    //The following objects are used to created the iframe in the web part and return the contents of the link to the IFRAME
    StringBuilder buffer = new StringBuilder(10240);
    StringWriter InnerWriter = new StringWriter(buffer);
    HtmlTextWriter BufferWriter = new HtmlTextWriter(InnerWriter);

    try
    {
    //Call method to write HTML to buffer
    WriteWebPartContent(BufferWriter);
    //Write HTML back to browser
    output.Write(buffer);
    }
    catch (System.Exception Ex)
    {
    }
    }

    /// <summary>
    /// This method generates the HTML to display the IFRAME and the page content inside it
    /// </summary>
    /// <param name="output">The HTMLTextWriter to send the output to</param>
    protected void WriteWebPartContent(HtmlTextWriter output)
    {
    try
    {
    string frame = "outputIFrame_" + base.Qualifier;

    output.AddStyleAttribute("display", "inline");
    output.AddAttribute(HtmlTextWriterAttribute.Id, frame);
    output.AddAttribute(HtmlTextWriterAttribute.Name, frame);
    output.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%");
    output.AddStyleAttribute(HtmlTextWriterStyle.Height, "100%");
    output.AddAttribute("frameBorder", "0");
    output.AddAttribute(HtmlTextWriterAttribute.Src, pageUrl);
    output.RenderBeginTag(HtmlTextWriterTag.Iframe);
    output.RenderEndTag();

    //If the web part is configured to show the page url then display it
    if (showPageUrl == true)
    {
    output.Write( "<BR>This web part is displaying content from the following URL: " + SPEncode.HtmlEncode(pageUrl) + "<BR>");

    output.Write( "<BR>EASTER EGG! Ski lifts open in 97 days from the date I reposted this article!<BR>");


    }
    }
    catch (System.Exception Ex)
    {
    }
    }
    }
    }


Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts