Andrew Connell [MVP SharePoint]
1728 Posts |  46 Articles |  5281 Comments
.NET  |  MCMS  |  SharePoint  |  Office System
AC's Blog Quick Links
SharePoint Quick Links
Article Categories
Archives
February, 2012 (2)
January, 2012 (12)
December, 2011 (6)
November, 2011 (3)
October, 2011 (17)
September, 2011 (8)
August, 2011 (6)
July, 2011 (7)
June, 2011 (13)
May, 2011 (9)
April, 2011 (15)
March, 2011 (1)
February, 2011 (6)
January, 2011 (5)
December, 2010 (11)
November, 2010 (6)
October, 2010 (12)
September, 2010 (5)
August, 2010 (4)
July, 2010 (5)
June, 2010 (6)
May, 2010 (11)
April, 2010 (11)
March, 2010 (9)
February, 2010 (9)
January, 2010 (3)
December, 2009 (10)
November, 2009 (15)
October, 2009 (15)
September, 2009 (7)
August, 2009 (4)
July, 2009 (10)
June, 2009 (8)
May, 2009 (2)
April, 2009 (9)
March, 2009 (6)
February, 2009 (16)
January, 2009 (6)
December, 2008 (12)
November, 2008 (12)
October, 2008 (27)
September, 2008 (13)
August, 2008 (14)
July, 2008 (14)
June, 2008 (12)
May, 2008 (23)
April, 2008 (12)
March, 2008 (15)
February, 2008 (13)
January, 2008 (12)
December, 2007 (10)
November, 2007 (8)
October, 2007 (15)
September, 2007 (20)
August, 2007 (21)
July, 2007 (16)
June, 2007 (8)
May, 2007 (25)
April, 2007 (16)
March, 2007 (18)
February, 2007 (18)
January, 2007 (12)
December, 2006 (16)
November, 2006 (13)
October, 2006 (18)
September, 2006 (22)
August, 2006 (27)
July, 2006 (23)
June, 2006 (23)
May, 2006 (23)
April, 2006 (9)
March, 2006 (17)
February, 2006 (15)
January, 2006 (23)
December, 2005 (31)
November, 2005 (32)
October, 2005 (38)
September, 2005 (53)
August, 2005 (30)
July, 2005 (63)
June, 2005 (30)
May, 2005 (59)
April, 2005 (29)
March, 2005 (74)
February, 2005 (27)
January, 2005 (22)
December, 2004 (32)
November, 2004 (42)
October, 2004 (39)
September, 2004 (20)
August, 2004 (14)
July, 2004 (27)
June, 2004 (40)
May, 2004 (5)
April, 2004 (6)
March, 2004 (16)
February, 2004 (26)
January, 2004 (23)
December, 2003 (7)
November, 2003 (14)
October, 2003 (20)
September, 2003 (4)
Post Categories
Add to Technorati Favorites

Managed Windows Shared Hosting

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
Gravatar 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
Gravatar 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.

# re: Using the ElementFile node in Feature definitions saves you in the deployment 3/27/2009 12:37 PM Michael Vasquez
Gravatar In reference to your blog http://www.andrewconnell.com/blog/articles/UsingCodeBehindFilesInSharePointSites.aspx

I packaged my feature to include all the aspx pages that my site will use. How do i modify my Element.xml to let my code behind know the location of all the other aspx pages in the feature. The only aspx page that seems to be visible is the one referenced by the custom action link. When the link is selected the site shows and the respective code behind is referenced, however when that code behind redirects to another aspx page with in the feature it fails with 404 error.

# re: Using the ElementFile node in Feature definitions saves you in the deployment 3/28/2009 7:57 AM AC [MVP MOSS]
Gravatar Michael-
Sounds like you didn't provision the other files. Files in a Feature are templates... you have to provision them into SharePoint using the <module> and <file> nodes to have them show up in the site.

# re: Using the ElementFile node in Feature definitions saves you in the deployment 1/18/2010 6:06 PM Shruti
Gravatar Hi Andrew, Is it possible to include 2 list definitions and 2 content type into one feature?
something like following...

<Feature
Id="912EFAF7-5951-4EF2-A6B5-26F2188AC1DC"
Title="Compound Request"
Version="1.0.0.0"
Scope="Site"
Hidden="false" ReceiverAssembly="CompoundOrder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d772fbab82fe6996"
ReceiverClass="CompoundOrder.Application.CompoundRequestReceiver" xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="CompoundRequest.xml" />
<ElementManifest Location="CompoundRequestList.xml" />
<ElementFile Location="CompoundRequestList\Active.aspx" />
<ElementFile Location="CompoundRequestList\AllItems.aspx" />
<ElementFile Location="CompoundRequestList\Byowner.aspx" />
<ElementFile Location="CompoundRequestList\DispForm.aspx" />
<ElementFile Location="CompoundRequestList\DueToday.aspx" />
<ElementFile Location="CompoundRequestList\EditForm.aspx" />
<ElementFile Location="CompoundRequestList\MyGrTsks.aspx" />
<ElementFile Location="CompoundRequestList\MyItems.aspx" />
<ElementFile Location="CompoundRequestList\NewForm.aspx" />
<ElementFile Location="CompoundRequestList\schema.xml" />

<ElementManifest Location="CompoundRequestItemsList.xml" />
<ElementFile Location="CompoundRequestItemsList\Active.aspx" />
<ElementFile Location="CompoundRequestItemsList\AllItems.aspx" />
<ElementFile Location="CompoundRequestItemsList\Byowner.aspx" />
<ElementFile Location="CompoundRequestItemsList\DispForm.aspx" />
<ElementFile Location="CompoundRequestItemsList\DueToday.aspx" />
<ElementFile Location="CompoundRequestItemsList\EditForm.aspx" />
<ElementFile Location="CompoundRequestItemsList\MyGrTsks.aspx" />
<ElementFile Location="CompoundRequestItemsList\MyItems.aspx" />
<ElementFile Location="CompoundRequestItemsList\NewForm.aspx" />
<ElementFile Location="CompoundRequestItemsList\schema.xml" />

</ElementManifests>
</Feature>

Problem with this, even though schema.xml file is reffering to the different content types both the lists are using the very first content type. (Both lists are using compoundRequest content type)

Without changing anything if I create 2 separate features(1 list definition and 1 content type) then it works fine.
Thank you so much in advance....


Post Feedback

Title:
Name:
Email:
(email will not be displayed)
Url:
Comments: 
Please add 2 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 irrelevant 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 - 2012 Andrew Connell
Creative Commons License 
This work is licensed under a Creative Commons License
Site design by Heather Solomon.

 
 
SharePoint 2010 Training
Looking for SharePoint 2010 training for developers, administrators, SharePoint Designer 2010 and end users? Look no further! My company, Critical Path Training offers the best SharePoint training around!