in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Ton Stegeman [MVP] weblog

July 2006 - Posts

  • File not found message in SharePoint 2007 when logged on as a reader

    Just a quick one this time. When you create a custom masterpage for your SharePoint environment and upload that into the masterpage gallery, you will have to publish it before readers will be able to access the portal. Otherwise they will get a “File not found” message when trying to access a page. The masterpage gallery itself is a SharePoint document library with versioning and approvals enabled. When you first upload a masterpage, the status is “Draft” and therefore only visible for administrators.

    Something that is very obvious afterwards, but took me (and other people) some time to realize.

  • Creating ContentTypes in SharePoint 2007 by using a feature

    In one of the previous posts I showed how you can add sitecolumns to a SharePoint 2007 site by using features. It is also possible to deploy content types using features. In this post I will describe how to do that. We will create 3 contenttypes; the first is called “Company Document” and has 2 fields: Region and Industry. The contenttypes “Proposal” and “Whitepaper” inherit from this “Company Document”. Proposal has 1 extra column called ClientName and Whitepaper has and extra column to store the publication date.

    One warning: SharePoint 2007 isn’t very informative in case you do something wrong in your sitecolumns or contenttypes. It simply does not appear in the list, leaving you wondering what is wrong. Be warned!

    Step 1 – Create the SiteColumns
    The first step is to create the site columns. Fields cannot be added directly to contenttypes, they have to be a sitecolumn. I will not describe how to deploy these columns (you can find that here). The feature xml looks like this:

        1 <?xml version="1.0" encoding="utf-8" ?>
        2 <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
        3   <Field ID="{7d2aeebd-ad31-43f2-9f9f-72d76759dd36}" 
        4       Name="Region" DisplayName="Region" StaticName="Region" Group="Company Metadata Model"
        5       Type="Choice" Sealed="TRUE" AllowDeletion="FALSE"
        6       SourceID="http://schemas.microsoft.com/sharepoint/v3/fields"
        7       Description="Identifies the region this document applies to">
        8     <CHOICES>
        9       <CHOICE>EMA</CHOICE><CHOICE>ASPAC</CHOICE><CHOICE>Americas</CHOICE>
       10     </CHOICES>
       11     <Default>EMA</Default>
       12   </Field>
       13   <Field ID="{05d891f3-5f35-41aa-bce0-40e37d08c2e3}" 
       14     Name="Industry" DisplayName="Industry" StaticName="Industry" Group="Company Metadata Model"
       15     Type="Choice" Sealed="TRUE" AllowDeletion="FALSE" FillInChoice="FALSE"
       16     SourceID="http://schemas.microsoft.com/sharepoint/v3/fields"
       17     Description="Identifies the industry that the document applies to" >
       18     <CHOICES>
       19       <CHOICE>Auto Dealerships</CHOICE><CHOICE>Auto Manufacturers</CHOICE>
       20     </CHOICES>
       21   </Field>
       22   <Field ID="{a898bf6c-bb0b-4451-b0f3-b6aa27223865}"
       23       Name="CustomerName" DisplayName="Customer Name" StaticName="CustomerName" Group="Company Metadata Model"
       24       Type="Text" Sealed="TRUE" AllowDeletion="FALSE"
       25       SourceID="http://schemas.microsoft.com/sharepoint/v3/fields"
       26       Description="Identifies the client for whom the document was prepared" />
       27   <Field ID="{b3c3f26e-a0c6-4607-8f45-5465c8fd67cb}"
       28       Name="PublicationDate" DisplayName="Publication Date" StaticName="PublicationDate" Group="Company Metadata Model"
       29       Type="Text" Sealed="TRUE" AllowDeletion="FALSE"
       30       SourceID="http://schemas.microsoft.com/sharepoint/v3/fields"
       31       Description="The official publication date for the document" />
       32 </Elements>

    You will need to give you sitecolumns a unique id (a GUID). These ID’s are used to reference the fields from the contenttype XML.
    I am still trying to figure out why we now have a Name and a StaticName for a field. If you know this, please let me know!

    Step 2 – Create a ContentType feature

    • Create a new subfolder “companycontenttypes” in folder “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES”.
    • Add a new file to this folder called “feature.xml”
    • The contents of this file look like this:
          1 <?xml version="1.0" encoding="utf-8" ?>
          2 <!-- _lcid="1033" _version="12.0.4017" _dal="1" -->
          3 <!-- _LocalBinding -->
          4 <Feature  Id="c36321e0-0107-43fa-85bf-5729f23963fc"
          5           Title="Company Content Types"
          6           Description="Company Content Types"
          7           Version="1.0.0.0"
          8           Scope="Site"
          9           xmlns="http://schemas.microsoft.com/sharepoint/">
         10   <ElementManifests>
         11     <ElementManifest Location="companycontenttypeswss.xml" />
         12   </ElementManifests>
         13 </Feature>

      Make sure you create a new unique ID for the feature. Please note the feature is scoped at the site level.
    • The element manifest is the name of the file in which we will create our contenttypes.

     Step 3 – Create the contenttypes

    • Create a new file in the same folder, with the value of the Location attribute of the ElementManifest element in the feature xml of ste 2.
    • In my case this xml looks like this:
          1 <?xml version="1.0" encoding="utf-8" ?>
          2 <!-- _lcid="1033" _version="12.0.4017" _dal="1" -->
          3 <!-- _LocalBinding -->
          4 <!--
          5 -->
          6 <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
          7   <ContentType ID="0x01010D"
          8       Name="Company Document"
          9       Group="Company Metadata Model"
         10       Description="Company document"
         11       Version="0">
         12     <FieldRefs>
         13       <FieldRef ID="{7d2aeebd-ad31-43f2-9f9f-72d76759dd36}" Name="Region" Required="TRUE"/>
         14       <FieldRef ID="{05d891f3-5f35-41aa-bce0-40e37d08c2e3}" Name="Industry" Required="TRUE"/>
         15     </FieldRefs>
         16   </ContentType>
         17   <ContentType ID="0x01010D0D"
         18       Name="Proposal"
         19       Group="Company Metadata Model"
         20       Description="Company proposal"
         21       Version="0">
         22     <FieldRefs>
         23       <FieldRef ID="{a898bf6c-bb0b-4451-b0f3-b6aa27223865}" Name="CustomerName" Required="TRUE"/>
         24     </FieldRefs>
         25   </ContentType>
         26   <ContentType ID="0x01010D0E"
         27       Name="Whitepaper"
         28       Group="Company Metadata Model"
         29       Description="Company whitepaper"
         30       Version="0">
         31     <FieldRefs>
         32       <FieldRef ID="{b3c3f26e-a0c6-4607-8f45-5465c8fd67cb}" Name="PublicationDate" Required="TRUE"/>
         33     </FieldRefs>
         34   </ContentType>
         35 </Elements>
      In this xml the 3 contenttypes are defined. One thing to be aware of is the ID of a contenttype. An ID has to be unique, and by using the correct syntax, you can set the inheritance of a contenttype. The ID of our base contenttype is “0x01010D”. This means that our contenttype inherits from “0x0101”, which is the out of the box SharePoint Document contenttype. Our Proposal inherits from our Company Document and therefore the ID starts with “0x01010D” followed by a unique identifier this Proposal.
      By setting the “Required” attribute, the fields will be required for a user to fill in when the contenttype is used in a list.

    Step 3 – Register and Activate the feature

    • Register the feature by using this command:
          stsadm -o installfeature -filename companycontenttypes\feature.xml
    • Activate the feature by using this command:
          stsadm" -o activatefeature -filename companycontenttypes\feature.xml -url http://companyintranet
      Please note that the contenttypes will be avaible in the site that is set with the -url parameter. They are available in the site and all it’s subsites.

    Step 4 – Test the contenttypes

    • Create a new document library in your site
    • Switch “Allow management of content types?” on in the advanced settings
    • Add the Proposal and Whitepaper contenttypes to the library
    • The “Columns” section of your document library should now look like this:
      Contenttypes

  • Activating Features in a site definition in SharePoint 2007

    In previous posts about sitecolumns and contenttypes I described how to create features to deploy sitecolumns and contenttypes to a site. The last step of this process is always to activate the feature using the STSADM activatefeature command. In my case I wanted to activate this feature automatically when I create a new site. The <Configuration> element of a site definition (onet.xml) contains 2 new elements: SiteFeatures and WebFeatures. Because my features have a “Site”  scope, I added them to the SiteFeatures.

    This is configured like this:

        1 <Configuration ID="0" Name="Publishing">
        2   <Lists>
        3   </Lists>
        4   <SiteFeatures>
        5     <!-- Activate SiteColumns -->
        6     <Feature ID="37b693b8-e650-44dd-88bb-497dc78de1f6" ></Feature>
        7     <!-- Activate ContentTypes -->
        8     <Feature ID="c36321e0-0107-43fa-85bf-5729f23963fc" ></Feature>
        9   </SiteFeatures>
       10   <WebFeatures>
       11   </WebFeatures>
       12 </Configuration>

    Please make sure that you activate the sitecolumns before the contenttypes!! A better way is to use the ActivationDependencies, but I haven’t figured that out yet.

    After an iisreset and creating a new site, I have the new contenttypes and sitecolumns available in that site. Because I added this to the site definition of a toplevel site in a site collection, they are automatically available in all subsites. Of course you can also activate the features for every subsite, but in my case it didn’t make sense to do it in every subsite separately.

    Now I never have to wonder if a new site collection will get my default site columns and content types. It is as easy as that!

  • SiteDefinitions in SharePoint 2007

    MOSS 2007 still uses site definitions, as in SharePoint 2003 technologies. The basic structure of these site definitions is still the same, although there have been a lot of changes. In this post I will decribe a number of these changes.

    Features
    A lot of the options of a site are now added to the sitedefinition by activating features. This makes the onet.xml and the filestructure of the site definition much cleaner. Registering ListTemplates in a site definition for example, only requires a specific feature to be activated from the onet.xml. The <Configuration> element in onet.xml now contains an element <WebFeatures>. Registering the listtemplate for the Document Library is now done by adding this line to this element:
    <Feature ID="00BFEA71-E717-4E80-AA17-D0C71B360101" >
    In SharePoint 2003, the schema files for the list had to be in the LISTS folder in every site definition, and the ListTemplate had to be registered in every onet.xml. Now you register schema of the list and the registration are part of a feature, that you activate from onet. Much cleaner, because there is only 1 place where the list is defined and registered.

    “Virtual” Site Definitions
    In SharePoint 2003, a sitedefinition is a folder named “SPS[your_name]” in the SPS folder \60\TEMPLATE\1033 and a registration in webtempsps.xml (or any other file called “webtemp*”. In SharePoint 2007, the folders for site definitions have moved to a special folder called “SiteTemplates”. Their name no longer needs to start with “SPS”. Apart from that you can now have ‘virtual’ site definitions. Such site definitions are a registration of a number of webs that will be provisioned the the site definitions is used. The “Corporate Intanet Site” and the “Internet Presence Web Site” are examples of such a site definition. They do not point to a specific folder, but to a manifest file (which is set in the “ProvisionData” attribute).
    In case of the Corporate Intranet Portal, this is a reference to the file called “PortalWebManifest.xml”. This file contains xml like the sample below:

    <portal xmlns="PortalTemplate.xsd">
        <web
     name="Home"
     siteDefinition="SPS"
     displayName="$Resources:spscore,PortalManifest_Home_DisplayName;"  description="$Resources:spscore,PortalManifest_Home_Description;">
            <webs>
                <web name="News" siteDefinition="SPSNHOME"   displayName="$Resources:spscore,PortalManifest_News_DisplayName;"   description="$Resources:spscore,PortalManifest_News_Description;" />
            </webs>
        </web>
    </portal>

    When this site definition is used, a site called “Home” is created, and for this site the subsites that are referenced in the <webs> element will be created. Nice way of packaging a number of sites into 1 single site definitions.

    ASPX pages

    The aspx pages in a site definition no longer contain code/HTML. They use SharePoint masterpages and page layouts. So instead of changing a lot of aspx pages on the file system, you just make your changes to the page layout or the masterpage. Nice! 


Need SharePoint Training? Attend a SharePoint Bootcamp!

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