IT tutorials
 
Technology
 

Sharepoint 2010 : Data Access Overview - Content Types (part 2) - Content Type Metadata

10/27/2013 9:18:18 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

2. Content Type Metadata

You’ve seen how content types are organized into a hierarchy and how inheritance determines the functionality that is enabled by a given content type. Now let’s take a look at the type of metadata, and therefore the types of functionality, that can be exposed by content types.

Workflow Associations

Workflows can be associated with content types and set to run in response to certain events. By attaching workflows to content types rather than individual lists, you can define business processes for specific types of data regardless of where the data is stored within a SharePoint site.

Document Template

For some types of content, particularly those based on Microsoft Office documents such as Word or Excel docs, custom templates can be specified that users can populate with relevant details. Details of such a template can be specified as content type metadata, allowing the template to be used wherever the content type is added to a document library.

Display, Edit, and New Forms

Each content type can define custom display, edit, and new forms allowing customization of the user interface presented at these stages. Various options are available for customizing these forms; however, from a content type perspective, it’s important to note that two properties exist for each form. For example, to set the Display form, you can use a DisplayFormTemplateName property and a DisplayFormUrl property. Which property you use depends on the level of customization that’s required. By setting the DisplayFormTemplateName property, you can specify a template that will be used by the DataForm Web part to render the appropriate view. However, if a greater level of customization is required, the DisplayFormUrl can be set to the URL for a custom Active Server Page Framework (ASPX) page, allowing a much greater degree of flexibility with the drawback that none of the usual SharePoint user interface elements will be present on the page by default.

Mobile Display, Edit, New Pages

New in 2010—SharePoint 2010 provides a number of new features for rendering content for mobile browsers. One example of this new functionality is the ability to specify custom forms for creating and editing content using mobile browsers at the content type level.

XML Documents

The ability to add practically any XML-based metadata to a content type is an incredibly powerful feature. Interestingly, some of the metadata already described, although accessible through the object model via dedicated properties, is actually attached to a content type via additional XML documents.

The following code sample shows how metadata can be added by creating a custom class that supports XML serialization and then setting properties on the class to contain the appropriate values. Using this technique, you can attach practically any additional data to a content type.

 static void Main(string[] args)
{
string siteUrl = "http://localhost";
Program p = new Program();
using (SPSite site = new SPSite(siteUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPContentType newContentType;
newContentType = p.CreateContentType(web, "MyFirstContentType", "Item");
CustomMetadata metaData = new CustomMetadata();
metaData.MyIntegerProperty = 46;
metaData.MyTextProperty = "Data stored as custom metadata";
p.AddCustomMetadata(metaData, newContentType);
metaData = null;
metaData = p.ReadCustomMetaData(newContentType);
Console.WriteLine(metaData.MyTextProperty);
}
}
Console.ReadLine();
}

void AddCustomMetadata(CustomMetadata data, SPContentType contentType)
{
XmlSerializer s = new XmlSerializer(typeof(CustomMetadata));
StringBuilder sb = new StringBuilder();
using (XmlWriter writer = XmlWriter.Create(sb))
{
s.Serialize(writer, data);
}
XmlDocument doc = new XmlDocument();
doc.LoadXml(sb.ToString());
contentType.XmlDocuments.Add(doc);
}

CustomMetadata ReadCustomMetaData(SPContentType contentType)
{
CustomMetadata data;
Type t = typeof(CustomMetadata);
var attrib = (XmlRootAttribute)t.GetCustomAttributes(
typeof(XmlRootAttribute), false).FirstOrDefault();
if (contentType.XmlDocuments[attrib.Namespace] != null)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(contentType.XmlDocuments[attrib.Namespace]);
using (StringReader sr = new StringReader(
contentType.XmlDocuments[attrib.Namespace]))
{
using (XmlReader rdr = XmlReader.Create(sr))
{
XmlSerializer s = new XmlSerializer(t);
data = (CustomMetadata)s.Deserialize(rdr);
}
}
return data;
}
else
{
throw new KeyNotFoundException();
}
}

[XmlRoot(Namespace="Http://www.chaholl.com/SP2010Apps/ContentTypesDemo")]
public class CustomMetadata
{
[XmlElement()]
public int MyIntegerProperty { get; set; }
[XmlElement()]
public string MyTextProperty { get; set; }
}
 
Others
 
- Sharepoint 2010 : Data Access Overview - Content Types (part 1) - Content Type Inheritance
- Windows 7 : Using CDs and DVDs - Using Disks that Already Contain Data (part 2) - Changing what happens when you insert a CD or DVD
- Windows 7 : Using CDs and DVDs - Using Disks that Already Contain Data (part 1)
- Windows 7 : Using CDs and DVDs - What Kind of Drive Do I Have?
- Windows 7 : Kernel Mode Installation and Build - Testing a KMDF Driver
- Windows 7 : Kernel Mode Installation and Build - Catalog Files and Digital Signature, Installing Featured Toaster
- Windows Phone 8 : Enterprise Phone Apps - Preparing Apps for Distribution, Building a Company Hub
- Windows Phone 8 : Enterprise Phone Apps - Application Enrollment Token , Registering Phones
- Windows Phone 8 : Enterprise Phone Apps - Installing the Certificate
- Windows Phone 8 : Enterprise Phone Apps - Buying a Symantec Code-Signing Certificate
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us