Tag Archives: Note

Provision SharePoint Fields in Elements.xml

I found a really nice blog that everyone should add it to their bookmark. I just reiterate here so I will not loose it.

<!--Single Line of Text-->
<Field id="{FDDC4E38-25E0-4FD9-92E7-D17F34A5AB12}" description="My Content ID of Item" staticname="ContentID" name="ContentID" displayname="ContentID" type="Text" group="Sample Site Columns" sourceid="http://schemas.microsoft.com/sharepoint/v3"/>

<!--Number-->
<Field ID="{13b3652a-d543-465d-91cb-a9d625637855}" StaticName="Read_Times" Name ="Read_Times" DisplayName ="Read_Times" Description="Read Time count of Item" Type="Number" Group ="Sample Site Columns" SourceID ="http://schemas.microsoft.com/sharepoint/v3"/>

<!--Date Time-->
<Field ID="{d076e4d5-c785-4c04-8b56-c1f021721749}" StaticName="CreateDate" Name="CreateDate" DisplayName="Create_Date" Description="Create Date of Item" Group="Sample Site Columns" Type="DateTime" Format="DateOnly" SourceID="http://schemas.microsoft.com/sharepoint/v3/fields"/>

<!--Multi Line of Text-->
<Field ID="{2ae59f08-0fb0-4a9c-8a31-a180161b1029}" StaticName="PublisherDescription" Name="PublisherDescription" Description="Publisher Description of Item" DisplayName="Publisher_Description" Type="Note" RichText="FALSE" NumLines="6" Group="Sample Site Columns" SourceID="http://schemas.microsoft.com/sharepoint/v3/fields"/>

<!--Rich Text HTML-->
<Field ID="{13cd0291-df15-4278-9894-630913e4d2b9}" StaticName="AccrediterDescription" Name="AccrediterDescription" DisplayName="Accrediter_Description" Description="Accrediter Description of Item" Type="Note" NumLines="6" RichText="TRUE" RichTextMode="FullHtml" Group="Sample Site Columns" SourceID="http://schemas.microsoft.com/sharepoint/v3/fields"/>

<!--Publishing HTML-->
<Field ID="{E2CC0231-FA6C-4F90-839C-118C304DFCF1}" StaticName="PMediaDescription" Name="PMediaDescription" DisplayName="MediaDescription" Type="HTML" RichText="TRUE" RichTextMode="ThemeHtml" Group="Site Columns" SourceID="http://schemas.microsoft.com/sharepoint/v3" UnlimitedLengthInDocumentLibrary ="TRUE"/>

<!--Publishing Image-->
<Field id="{148e8191-afe7-4422-b1d1-7202eda667f1}" description="Image 1 link of Item" staticname="PImageID1" name="PImageID1" displayname="Image_ID1" type="Image" group="My Site Columns" sourceid="http://schemas.microsoft.com/sharepoint/v3" richtext="TRUE" richtextmode="ThemeHtml"/>

<!--Hyperlink or Image-->
<Field ID="{635a2031-2088-4413-b54e-d2af5daf08bf}" StaticName="ImageAuthor" Name="ImageAuthor" DisplayName="Image_Author" Description="Author Image" Type="URL" Format="Image" Group="Sample Site Columns" SourceID="http://schemas.microsoft.com/sharepoint/v3/fields"/>

<!--Boolean-->
<Field ID="{11018312-58f9-4eb0-867d-71298f82d98d}" Name="isActive" StaticName="isActive" DisplayName="isActive" Description="Select if Item is Active" Group="Sample Site Columns" SourceID="http://schemas.microsoft.com/sharepoint/v3" Type="Boolean">
   <default>0</default>
</Field>

<!--Choices-->
<Field ID="{67f8faa4-e3ee-44bf-a3b4-6e7fc9c6b9fe}" Name="Market" StaticName="Market" DisplayName="Market" Description="Market of the Country" Group="Sample Site Columns" SourceID="http://schemas.microsoft.com/sharepoint/v3" Type="Choice">
   <choices>
      <choice>Gold</choice>
   </choices>
</Field>

<!--Multi Select-->
<Field Type="MultiChoice" DisplayName="Labels_Selected" FillInChoice="FALSE" Group="Sample Site Columns" ID="{2fdf0ba7-0052-4e9f-80f6-e7669ac4ae4f}" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="LabelsSelected" Name="LabelsSelected">
</Field>

<!--Lookup Column-->
<Field Type="Lookup" ID="{FE45AC76-C0E2-46C8-A047-E8C43C10315C}" Name="LU_Country" StaticName="LU_Country" DisplayName="LU_Country" Required="FALSE" List="Lists/Region Country Master" ShowField="RollOutCountry" UnlimitedLengthInDocumentLibrary="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3/fields" Group="Sample Site Columns"/>

<!--Multi Lookup Column-->
<Field Type="LookupMulti" Mult="TRUE" ID="{85062ACF-315B-460A-B756-2230A5FE082F}" Name="LU_Language" StaticName="LU_Language" DisplayName="LU_Language" Required="FALSE" List="Lists/Language Master" ShowField="Title" UnlimitedLengthInDocumentLibrary="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3/fields" Group="Sample Site Columns"/>

<!--Lookup with Additional Field Lookup column-->
<Field Type="Lookup" ID="{9AA2985D-AA17-4EA2-9556-9B0E112A64F6}" Name="LU_ApplicationType" StaticName="LU_ApplicationType" DisplayName="LU_ApplicationType" Required="FALSE" List="Lists/Application Type" ShowField="ApplicationType" UnlimitedLengthInDocumentLibrary="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3/fields" Group="Sample Site Columns"/>

<Field Type="Lookup" ID="{668D51C4-804D-43E7-8211-950AE3BCD9A3}" Name="LU_ApplicationType_ID" StaticName="LU_ApplicationType_ID" DisplayName="LU_ApplicationType_ID" List="Lists/Application Type" ShowField="ApplicationTypeID" FieldRef="9AA2985D-AA17-4EA2-9556-9B0E112A64F6" ReadOnly="TRUE" UnlimitedLengthInDocumentLibrary="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3/fields" Group="Sample Site Columns"/>

Reference

http://sharpointpractice.blogspot.com/2011/08/sharepoint-field-types-elementsxml.html

Advertisements

Create Managed Metadata column (TaxonomyFieldType) in Visual Studio

In this article, I would like to show you on how to create Managed Metadata column programmatically in Visual Studio.
Below is the list of steps:

  1. Open Visual Studio 2010 > File > New Project > Empty SharePoint Project, enter the Project Name and Location. Then click OK.timer1
  2. In SharePoint Customization Wizard, Enter your local site URL and Select Deploy as sandboxed solution. Then click Finish.timer2
  3. Right click on the project in Solution Explorer, then select Add > New Item > Site Column. Then enter the Site Column Name.
  4. Edit Elements.xml to look like:
    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
          <Field ID="{a1f36e30-5e09-4357-9db1-f0819183627d}"
              Type="TaxonomyFieldType"
              DisplayName="BusinessUnit"
              ShowField="Term1033"
              Required="TRUE"
              EnforceUniqueValues="FALSE"
              Group="Custom Columns"
              StaticName="BusinessUnit"
              Name="BusinessUnit"/>
          <Field
              ID="{d6594a04-2987-416a-b2ae-e7fd13c48df4}"
              Name="BusinessUnit_1" StaticName="BusinessUnit_1"
              SourceID="http://schemas.microsoft.com/sharepoint/v3/fields"
              Type="Note"
              DisplayName="BusinessUnit_1"
              Group="Custom Columns" ShowInViewForms="FALSE" Required="FALSE" Hidden="TRUE" />
    </Elements>
    
  5. Mapped the site column to the Managed Metadata term group and set when Feature Activated.
            public override void FeatureActivated(SPFeatureReceiverProperties properties)
            {
                SPSite site = properties.Feature.Parent as SPSite;
    
                // Map Managed Metadata site columns
                Guid fieldIdBU = new Guid("{A1F36E30-5E09-4357-9DB1-F0819183627D}");
                Guid noteFieldIdBU = new Guid("{d6594a04-2987-416a-b2ae-e7fd13c48df4}");
                MapManagedMetadataField(fieldIdBU, noteFieldIdBU, site, "Managed Metadata Service", "People", "Business Unit");
            }
    
            private void MapManagedMetadataField(Guid fieldId, Guid noteFieldId, SPSite site, string sTermStore, string sTermGroup, string sTermSet)
            {
                if (site.RootWeb.Fields.Contains(fieldId))
                {
                    TaxonomySession session = new TaxonomySession(site);
    
                    if (session.TermStores.Count != 0)
                    {
                        var termStore = session.TermStores[sTermStore];
                        var group = GetByName(termStore.Groups, sTermGroup);
                        var termSet = group.TermSets[sTermSet];
                        TaxonomyField field = site.RootWeb.Fields[fieldId] as TaxonomyField;
    
                        // Set Manage Metadata's Text field to Note field
                        field.TextField = noteFieldId;
    
                        // Connect to MMS
                        field.SspId = termSet.TermStore.Id;
                        field.TermSetId = termSet.Id;
                        field.TargetTemplate = string.Empty;
                        field.AnchorId = Guid.Empty;
                        field.Update();
                    }
                }
            }
    
            private Group GetByName(GroupCollection groupCollection, string name)
            {
                if (String.IsNullOrEmpty(name))
                {
                    throw new ArgumentException("Not a valid group name", "name");
                }
                foreach (var group in groupCollection)
                {
                    if (group.Name == name)
                    {
                        return group;
                    }
                }
                throw new ArgumentOutOfRangeException("name", name, "Could not find the group");
            }
    

Why do I have to add Note field type ? If you don’t add it, you will have an issue as per my previous article.

%d bloggers like this: