tirsdag den 22. december 2009

Turn on the Developer Dashboard with stsadm

In my opinion, this stsadm command is slitely more elegant than the example of console application that uses SPWebService and SPDeveloperDashboardSettings.

It activates a Developer dashboard icon in the upper right corner of any page:
stsadm -o setproperty -pn developer-dashboard -pv OnDemand

søndag den 20. december 2009

SharePoint 2010: custom content type & page layout

Creating SharePoint 2010 features and web parts in Visual Studio 2010 is extremely fast and a lot of fun. There is a template for creating new content type, and it is very easy to use. There is no template for creating master pages and page layouts. As most of the projects, I'm involved in, require development of one or more master pages and page layouts, I thought that it would be a good idea to figure that out.

I created an empty project in Visual Studio in order to create new NewsPage content type, some custom columns and page layout. Although I would normally create a feature containing both the content type and page layout, I decided to create two features; Feature1 and Feature2, no. 1 for the content type, and no. 2 for the page layout:
1. Open VisualStudio 2010
2. Click on File->New project
3. Choose "Empty SharePoint Project" from the template list and click "OK"
4. Choose your local SP2010 site as the site to debug
5. Choose sandboxed deployment
6. In solution Explorer rightclick on "Features" node and choose "Add feature"
7. When "Feature1" is created, rightclick on "Features" again and choose "Add feature"

Then I created a "NewsPage" content type:
1. Rightclick on your project and choose "Add"->"New item"
2. Choose "Content Type" from the list and click on "Add"
3. Choose "Article page" from the drop down menu and click on "Finish"
4. Open Elements.xml and change the "Name" to NewsPage
5. Change "Group" and "Description" too

Add custom fields to NewsPage content type - Elements.xml should look like this (without br tag):

Deploy the NewsPage content type to the site:
1. Open the Feature1.feature node (under Feature1) and fill out the name and Description for the feature. Check if the newly created content type is placed in "Items in the Feature" window.
2. Rightclick on the project and choose "Deploy"
3. Open the site, and check if the feature is on the list of features on Site collection features page in Site Settings
4. You should also be able to see NewsPage content type on Site Settings->Site content types page

That was an easy one. Let's create a page layout that has NewsPage content type:
1. Rightclick on the project and choose "Add"->"New item"
2. Choose "Empty Element" from the list
3. Rightclick on the project and choose "Add"->"New item" again
4. Choose "Module"
5. Rename "Sample.txt" to "NewsPage.aspx"
6. Open NewsPage.aspx and paste this code:

(without br tag):


Only Title and News Category fields are added, and you can add other fields later.
It's imortant to define NewsPage.aspx as NewsPage content type and deploy it as Feature2 to the site:

1. Open Elements.xml (under Module1)
2. Paste this code:

(without br tag):


3. Open Feature2.feature and fill the title and description of the feature
4. Check also if EmptyElement1 is part of the Feature2
5. Rightclick on the project an choose "Deploy"
6. Check the Output window in VisualStudio if the deployment is finished
7. Open the site in browser and open Site Settings
8. Open "Master pages and page layouts" to check if NewsPage.aspx is on the list as the NewsPage content type

Other Things I Wrote
Style with Content Query
Customize Content Query
SharePoint 2013 JavaScript - Add List with Columns