« Older Entries Newer Entries » Subscribe to Latest Posts

10 Sep 2010

Get only publishing pages in your search results in SharePoint 2010

Posted by Alexander. No Comments

Building Internet-facing websites in SharePoint 2010 is all about the publishing pages. But the standard search functionality in SharePoint will give you all kind of results back which points to SharePoint parts like for example  listings, listitems, images and other stuff.

But those results are not suited when building internet-facing websites. In most cases only the pages itself are allowed to be returned in your search results. SharePoint (2007 and 2010) offers the possibility to define a so called search scope. In a search scope you are able to define what needs to be searched through, what is required and what is excluded.  Such a scope can be made under the search service application in Central Administration or via the site settings of your web application.

To define a search scope which only crawls through the publishing pages of your internet-facing website, you will need to define the following rules:

  1. Create a rule with the following settings:
    1. Scope Rule Type is “Web Address”
    2. Web Address Folder is “http://yoururl”
    3. Behaviour is “Include”
  2. Create a second rule with the following settings:
    1. Scope Rule Type is “Property Query”
    2. Property Query is “contentclass = STS_ListItem_850″
    3. Behaviour is “Require”

Especially the last rule causes only to return the publishing pages.

7 Sep 2010

Deployment using PowerShell for SharePoint 2010

Posted by Alexander. No Comments

I have been working on some PowerShell script to deploy multiple solutions in SharePoint 2010 for customer projects. The script uses an prefilled xml file containing information for setting up your deployment easily on any server. Currently the script expects that your customer project contains a separate solution for the sitedefinitions and one ore more other solutions for installing any kind of features, components or page layouts. The script depends on a configuration xml file.

The actual deployment PowerShell script contains some methods for retracting, deleting, installing and deploying solutions. It does the deployment as follow:

1) retracts and removes the solution containing the site definitions
2) installs and deploys the solution containing the site definitions
3) checks if the web application exists. If not it is created (without a site collection)
4) retracts and removes the other solutions (defined in the xml file)
5) installs and deploys the other solutions

The scripts are released and maintained op codeplex. http://deploymentpowershell.codeplex.com/

Last but not least i want to thank some of the blogposts i have been reading about Powershell deployments. In particular the post of Stef van Hooijdonk

4 Jul 2010

SharePoint 2007 vs SharePoint 2010 comparison

Posted by Alexander. No Comments

Thanks to Richard Harbridge based on Microsoft documentation spread all over the Microsoft website, he accomplished to setup a very good comparison between SharePoint 2007 and SharePoint 2010.

He catagorized over Sites, Communities, Content, Search, Insights, Composites, Office 2010, Architecture, Web Services/OM, Editions and Administration.

http://www.rharbridge.com/?page_id=103

1 Jul 2010

Create Additional Columns for a Lookup field to a list using the Field Element

Posted by Alexander. 1 Comment

SharePoint 2010 offers a lot of new functionality for listings. One of them is “Additional Columns”. So what does it mean? Let’s say we have two lists called Provinces and Cities. Each City is in one of the Provinces.

This means that you create a lookup field from the Cities list to the Provinces list.  But i want to see the title and the province code of the Province. This is established using so called additional columns.

additionalcolumns1

Goto the list settings of the Cities list and add a new column. Call that column Province and set the type to Lookup. Now you will get options for additional columns. Select the Provinces list from the dropdown box and choose the field Title as value for that column. Now indicate the ProvinceCode field as an additional column.

additionalcolumns2

When returned to the list settings you will notice that a lookup field is created called Province and a lookup field called Province:ProvinceCode. That last field is the additional column. When a province is selected for a city the additional field from the refered province item is shown in the city item.

When you create a solution for a customer you will be creating definitions of Fields, ContentTypes and Lists. To create a lookup field and an additional column is as follow:

  <Field ID=”{2E652DA6-D53B-4C5F-8C98-1ADCB98F1E71}”
   Name=”Province”
   DisplayName=”Province”
   Type=”Lookup
   FieldRef =”ID”
   ShowField =”Title
   Required=”TRUE”
   Group=”MyFields”
   List=”Lists/Provincies“>
  </Field>

  <Field ID=”{55b4c728-dc8c-4255-bcee-9ffa6ee24020}”
  Type=”Lookup”
  DisplayName=”Province:ProvinceCode”
  List=”Lists/Provincies
  ShowField=”ProvinceCode”
  FieldRef=”{2e652da6-d53b-4c5f-8c98-1adcb98f1e71}
  ReadOnly=”TRUE
  Name=”Province_x003a_ProvinceCode“>
  </Field>

You will notice a few things:

a) The Field Province is needed before the additional field is created. The additional field refers to the Field Province by the FieldRef property.
b) The List property of both Field elements referes to the Provinces list.
c) The Name property contains the value Provincie_x003a_ProvinceCode which is actually the Name of the Field Province, the “:” character translated to _x003a_ and the name of the field ProvinceCode which is refered by the additional column.
d) The ReadOnly attribute fo the additional column is set to TRUE. You are not able to change additional columns. They are only retrieved as extra data from the refered list.

Add both Field elements as a FieldRef to your ContentType and schema.xml file of the list.

Because the Province:ProvinceCode column is now part of the Cities list you are able to query it by for example CAML code. 

SPList list = site.RootWeb.Lists["Cities"];
SPQuery query = new SPQuery();

query.Query = string.Format(@”
                                <Where>
                                    <Eq>
                                        <FieldRef Name=’Provincie_x003a_SVnProvinceCode‘ />
                                               <Value Type=’Lookup’>{0}</Value>
                                    </Eq>
                                </Where>”,
                               4);

 SPListItemCollection cityCollection = list.GetItems(query);

In stead of getting the cities based on the title of the province, you have the ability to do it based on the province code.

22 Jun 2010

SetAvailablePageLayouts generates “Failed to compare two elements in the array”

Posted by Alexander. No Comments

SharePoint offers a great method on the PublishingWeb object called SetAvailablePageLayouts. With this method you are able to set the list of page layouts available to the users of your SharePoint website. Mostly we use this method inside the FeatureActivated method of an SPFeatureReceiver derived class. The code is as follow:

System.Collections.Generic.List<PageLayout> allowedPageLayouts = new System.Collections.Generic.List<PageLayout>();
allowedPageLayouts.Add(publishingSite.PageLayouts["/_catalogs/masterpage/Home.aspx"]);
allowedPageLayouts.Add(publishingSite.PageLayouts["/_catalogs/masterpage/Article.aspx"]);
allowedPageLayouts.Add(publishingSite.PageLayouts["/_catalogs/masterpage/News.aspx"]);
allowedPageLayouts.Add(publishingSite.PageLayouts["/_catalogs/masterpage/FAQ.aspx"]);
publishingWeb.SetAvailablePageLayouts(allowedPageLayouts.ToArray(), true);

Last week i did implemented this again for a project and it causes a nasty error “Failed to compare two elements in the array”. Looking on the internet was not really helpfull till somebody pointed me out that it could be caused by an invalid page i was trying to set as available. The strange thing was that i tested all page templates and could not find any mistake.

After some time i suddenly saw the problem. The page templates where added using a feature. In the elements.xml file each page template was defined by a <Module />, <File /> and <Property /> elements. One of the properties refers to a Content Type by its name and its Id. It seems that i forgot an# sign  in the PublishingAssociatedContentType element.

<File Path="News.aspx" Url="News.aspx" Type="GhostableInLibrary">
<Property Name="Title" Value="$Resources:mysolution,PageLayout_News_Title" />
<Property Name="MasterPageDescription" Value="$Resources:mysolution,PageLayout_News_Description;" />
<Property Name="ContentType" Value="$Resources:mysolution,ContentType_News_DisplayName" />
<Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/News.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/News.png" />
<Property Name="PublishingAssociatedContentType" Value=";#$Resources:svn,ContentType_SVnNews_Name;;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D0041b83af6a3dd4e90a5e3552f14065687008437ce3f2cca491eadb900969009f447;#"/> </File>

It still added the page template and looking closer to the template list you could see that it wasn’t attached to its Content Type. Hopefully this post will help you when you encounter the same error in your solution.