List feature之创建自已的 Document Library Feature

From:http://www.cnblogs.com/al-zerone/archive/2007/11/15/960679.html

 

List feature之创建自已的 Document Library Feature

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 documentation 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 MOSS 2007 documentation.)

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.

Congrats!  You made your own custom Feature!

posted on 2009-11-26 22:01  黑木 Kang  阅读(494)  评论(0编辑  收藏  举报

导航