How to: Add a Content Type to a Site
How to: Add a Content Type to a Site

You can specify content types to include in a site definition, so that each time a user provisions a site of that type, Windows SharePoint Services makes those site content types available on the site by default.

Site definitions can be included in Features. For more information, see Working with Features.

After a user provisions a site, you can add content types to that site through the Windows SharePoint Services object model.

Specifying Content Types in a Site Definition

To specify a content type to include in a site definition, you first create the content type as a separate Feature, and then reference that Feature in the site definition.

To specify a content type to included in a site definition

  1. Create the content type as a separate Feature.

    For more information, see Working with Features.

  2. Reference that Feature in the feature that defines your site:

    1. In your site Feature, open the XML file that defines your site.

    2. In the Project element, under the Categories and Category elements, add a reference to the content type Feature in either the SiteFeatures or WebFeatures element. For example:

      <SiteFeatures>

      <Feature ID="00BFEA71-1C5E-4A24-B310-BA51C3EB7A57" />

      <Feature ID="695B6570-ACDC-4A8E-8545-26EA7FC1D162" />

      </SiteFeatures>

      <WebFeatures>

      <Feature ID="00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5" />

      <Feature ID="00BFEA71-E717-4E80-DEAF-D0C71B360101" />

      </WebFeatures>

Adding Content Types to a Provisioned Site

You can add content types to a provisioned site through the Windows SharePoint Services object model.

To add a content type to a provisioned site

  1. Use the AvailableContentTypes method to access the content types that are available for the site. This method returns an SPContentTypeCollection object.

  2. Create a SPContentType object using the SPContentType method.

  3. Use the Add method to add the SPContentType object to the site content type collection.

See Also

Community Content

How to: Access list and its values from SharePoint Site
Added by:Hemendra Patel

Purpose:

This article describes basic knowledge required to get one started with SharePoint programming model. This article allows SharePoint developers to take their experience to next level for developing cool webparts.

All you need to know is how to get site reference. You can get that with following chunk of code

SPSite mySite = new SPSite(URL); // Where URL is sharePoint site URL
SPWeb myWeb = mySite.OpenWeb()
{
// Do stuff here
}

Now, we got the reference to site and would like to see all Lists with-in site... We can achive this with little bit extension to code mentioned above.

SPSite mySite = new SPSite(URL); // Where URL is sharePoint site URL
SPWeb myWeb = mySite.OpenWeb()
{
// Do stuff here
string output ="";
foreach(SPList list in myWeb.Lists)
{
output += "<a href='" +list.DefaultView.Url.ToString() + "'>"+ list.Title + "</a> has "+list.Items.Count+" Items<br>";
}
}


Code above will scan through all lists and create html for each list items and it's record count. Now if you know which list you want to work with then you do not need to iterate full list. you can do following to access list by name.

  
SPSite mySite = new SPSite(URL); // Where URL is sharePoint site URL
SPWeb myWeb = mySite.OpenWeb()
{
// Do stuff here
SPList myList= myWeb.Lists["myListName"]; // Where myListName is sharePoint List name under URL
  foreach (SPListItem myRec in myList)
{
string mycolumn = myRec["ColumnName"].ToString(); // Get data from List Item record
  }
}

That's It... Now you know how to access list and its values from SharePoint Site. You can now build some custom webparts reading your LOB data and fusioning it with SharePoint Content.


Good Luck!!

MyProfile: https://mcp.support.microsoft.com/profile/PATEL1

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View