Andrew Connell [MVP MOSS]
1402 Posts |  39 Articles |  3659 Comments
.NET  |  MCMS  |  SharePoint  |  Office System
SharePoint Quick Links
Article Categories
Archives
Post Categories


Add to Technorati Favorites

WSS v3 Feature definitions (feature.xml) files contain a section that points to files that do most of the heavy lifting of a Feature: <ElementManifests />. This section is where you specify your element manifest files that contain CAML markup that is processed as instructions upon Feature activation. These element manifest files are deployed using the <ElementManifest> element.

However there is a lesser known element that you can use in this same location to your advantage. The <ElementFile /> element, also a child to the <ElementManifests /> element tells SharePoint about other files that are part of the Feature. What kind of files would you put in here? Things such as master pages, page layouts, images, style sheets, Web Part definition files, etc. The Feature doesn't do anything with these files... it just is made aware that they "belong" to the Feature.

"But I'm already using images in my Feature without this and I'm not having any problems... why do I need it?" Good question...

When you package everything up in a WSS solution package you list your Feature's definition file within the manifest.xml file (using the <FeatureManifests /> node) which contain the instructions to SharePoint of what to do with the files within the package (*.wsp). If you have additional files that go along with your Feature, you should be listing them in the manifest.xml file as well using something like <TemplateFiles /> or <RootFiles /> (the former is preferred). But, if you listed all the files that were part of the Feature using the <ElementFile /> nodes within the Feature definition, you wouldn't have to list them here. Why? Because SharePoint will look at the definition and see those are files that are part of the Feature itself so the solution framework will deploy those as well.

Take the following for example. This is a sample Feature that provisions a mater page, page layout, preview images for each, a stylesheet and an image. The element manifest file provisions all these files as uncustomized instances in the a Publishing site.

<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
         Id="D56F0D2D-0107-424d-AA0D-7120329A23E6"
         Title="ACME: Provisioning Master Pages and Page Layouts"
         Hidden="FALSE"
         Scope="Site"
         Version="1.0.0.0">

  <ElementManifests>
    <ElementManifest Location="elements.xml" />
    <ElementFile Location="MasterPages\ACMETmp.master" />
    <ElementFile Location="MasterPages\ACMEMasterPreviewTmp.gif" />
    <ElementFile Location="Styles\ACMETmp.css" />
    <ElementFile Location="Styles\ACMETmp.gif" />
    <ElementFile Location="PageLayouts\ACMEPressTmp.aspx" />
    <ElementFile Location="PageLayouts\ACMEPressPreviewTmp.gif" />
  </ElementManifests>
    
</Feature>

Now, the manifest.xml file for the solution package is quite simple as it only points to the Feature definition within the packaged WSP file:

<?xml version="1.0" encoding="utf-8" ?>
<Solution xmlns="http://schemas.microsoft.com/sharepoint/"
          SolutionId="7DFC3075-45C0-4946-9E5F-CA6BBC749C64"
          DeploymentServerType="WebFrontEnd"
          ResetWebServer="FALSE">
  <FeatureManifests>
    <FeatureManifest Location="ACMESite\feature.xml"/>
  </FeatureManifests>
</Solution>

Consider this approach when building Features... it saves you a lot of headaches when packaging up your Features.

Technorati tags: , ,
posted on Thursday, September 27, 2007 3:19 PM

Feedback

# re: Using the ElementFile node in Feature definitions saves you in the deployment 9/27/2007 9:52 PM John Ross
Gravatar Very nice!

# re: Using the ElementFile node in Feature definitions saves you in the deployment 9/28/2007 3:24 AM Robin
Gravatar Thanks! Very useful ;)
Blogged you at http://glorix.blogspot.com/2007/09/creating-features-using-elementfile.html

 re: Using the ElementFile node in Feature definitions saves you in the deployment 10/9/2007 2:48 AM Alex
Gravatar Hello Andrew,

It's a nice information but, do you know if i could deploy a custom field type as a feature?

Thanks for any help

# re: Using the ElementFile node in Feature definitions saves you in the deployment 10/9/2007 7:35 AM AC [MVP MOSS]
Gravatar Alex-
Custom field types aren't deployed using a Feature. The field definition goes in the 12\TEMPLATE\XML directory and the assembly goes in the GAC. Recycle IIS and you're good to go. Field types aren't activated... they are global to an entire farm once deployed.

 re: Using the ElementFile node in Feature definitions saves you in the deployment 1/4/2008 8:57 AM Karine
Hi Andrew,
Thanks for the tip. But my feature contains aspx pages that I want to deploy to TEMPLATE\LAYOUTS\MyFeature\mypage.aspx. How should I define the Location in the ElementFile element?
Thanks in advance for your help

# re: Using the ElementFile node in Feature definitions saves you in the deployment 1/4/2008 9:11 AM AC [MVP MOSS]
Gravatar Karine-
You don't include those things in the Feature definition. You only put stuff in the <ElementFile> node for stuff IN the Feature.

 re: Using the ElementFile node in Feature definitions saves you in the deployment 1/4/2008 2:23 PM karine
Hi Andrew,
Thanks for your quick reply. So this means that you only can include files in the <ElementFile> node that PHYSICALLY are part of the feature. Application pages that LOGICALLY are part of the feature cannot be included.
Anyway thanks for your good work and good luck with your book!
Kind regards,
Karine

# re: Using the ElementFile node in Feature definitions saves you in the deployment 4/10/2008 6:20 AM Anil
Gravatar Hi

I am trying to deploy a site column based on a custom field type using the feature.

My Custom field type needs a text parameter called Metadatatype.

I am not sure when we declare site columns in elements xml file, how do we pass these parameter value.

I got a work around by using feature receiver and create site columns progarmatically.

but is there a wayto create through the xml file

Thank You



# re: Using the ElementFile node in Feature definitions saves you in the deployment 4/10/2008 10:10 AM AC [MVP MOSS]
Gravatar Anil-
Try using something like my custom command to see what the XML would look like if you did it using the browser? http://andrewconnell.com/blog/articles/MossStsadmWcmCommands.aspx

# re: Using the ElementFile node in Feature definitions saves you in the deployment 5/12/2008 5:22 AM kazutsugu
Gravatar Hi Andrex,
> The element manifest file provisions all these files as uncustomized instances in the a Publishing site.

Can I ask what exactly you mean by this “provisions”?

Do you not think we need something like this (I simplified it a lot), in addition to what you have here, for the masterpage for instance to be actually provisioned?

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="ACMETmp.master"
Url="_catalog/masterpage">
<File Url="MasterPages\ACMETmp.master">
<Property ...
</File>
</Module>
<Module Name="PreviewImages"
Url="_catalogs/masterpage/Preview Images">
<File Url="MasterPages\ACMEMasterPreviewTmp.gif"/>
</Module>
</Elements>

Thanks a lot in advance for your help.

# re: Using the ElementFile node in Feature definitions saves you in the deployment 5/12/2008 9:28 AM AC [MVP MOSS]
Gravatar Kazutsugu-
Provisioning a file means creating an instance of it in the database based off a template on the file system. Read this for more info:
http://msdn.microsoft.com/en-us/library/cc406685.aspx

You definately need more than what I provided in the blog post. The point of the blog post was to simply show the <ElementFile> node.

Post Feedback

Title:
Name:
Email:
(email will not be displayed)
Url:
Comments: 
Please add 7 and 5 and type the answer here:    
All Comments Are Filtered & Moderated
Unfortunately comment spammers are just too effecient and are constantly dirtying up blogs with irrelivant and unwanted comments trying to improve their standing on search engines. All comments on this blog are moderated. I do not censor comments, but I don't approve comments with vulger language or those soliciting products. Most of the time comments are approved within a few hours of being submitted with the only exception when I'm traveling.

Why are you asking for my email address?
The only reason I'm asking for your email address, which isn't required to submit a comment, is to provide a gravatar if you've created an account for yourself and associated your email address with a small image. If you have a gravatar created for the email address you submit, it will appear next to your comment. Otherwise nothing will appear.

What is a gravatar?
A gravatar is a "globally recognized avatar." You can get more information about gravatars, as well as create your own for free, at www.gravatar.com. You can also view my gravatar here.


Copyright © 2003 - 2008 Andrew Connell
Creative Commons License 
This work is licensed under a Creative Commons License
Site design by Heather Solomon.

 
 
MOSS WCM Training
Looking for MOSS 2007 WCM developer training? Look no further! I teach my 4-day hands-on and 5-day online WCM classes for developers I offer through the Ted Pattison Group.

Get more information on the WCM courses!


Upcoming Classes
 Hands-on WCM:
 » Tampa, FL
   Jan 12-15, 2009
 Online WCM:
 » Dec 8-12, 2008


» Register today!

JAX Office Geeks
Jacksonville Office Geeks (JOG)
JOG is a special interest group in Jacksonville, FL dedicated to bringing the local SharePoint commnity together to share tips, tricks, ideas and best practices for developing solutions on the SharePoint platform.

Next meeting details...
When:
Thur. Nov 20th, 2008
  6-8p EDT
Topic:
Creating & Debugging Custom Timer Jobs in WSS

Speaker:
Andrew Connell, MVP MOSS

RSVP Today!


» Subscribe to the JOG newsletter