Online Training On SharePoint
                      

Wednesday, 28 April 2010

Error while running the STSADM and PowerShell Commands

I was trying to work with solutions using STSADM command. But STSADM Commands was giving the error saying that "Object Reference not set to an instance of an object" as shown:

When I started the PowerShell it has given a error saying that "The Local Farm is not accessible. Cmdlets with FeatureDependencyId are not registered." as shown

On further investigation I found that some how my access on the SharePoint Config DB was removed. After giving the access this started working fine.

Monday, 26 April 2010

Restricting the results based on a Content Type for FAST Search for SharePoint 2010

We can restrict to show the search results based on a specific content type in FAST Search for SharePoint 2010. I had a requirment where I need to filter the data and show results only from a specific library. This library was associated to a particular content type. The easiest way to acheive this to do a query and filter the data based on the content type. I will now explain how we can do this. First we need to create a property in FAST Search. To see the detailed description on how to create a managed property check here
The important thing here is we need to select the ows_contenttype crawled property as crawled property:

Also we need to make sure to check the Query Property while creating this managed property:

Now once this is done we need to do a full crawl so that we can do query on this managed property.

I have created my managed metadata with the name contenttypeproperty. Also lets asssume my content type name is democontenttype. Now we can do a search like
test contenttypeproperty:democontenttype
With this query the search will only return the items having the content type as democontenttype.

On the similar lines if we just need to return the documents in the search results we can change the query to:
test contenttypeproperty:document
With this query it will only be showing the documents in the search resutls core web part.

Wednesday, 21 April 2010

Contributor getting error while adding specific Web Parts in SharePoint 2010

With SharePoint 2010 the SharePoint Groups inheriting the contributor permission can not add specific web parts (as an example Content Editor Web Part) into a SharePoint Page. The users will get the following error (A Web Part or Web Form Control on this Page cannot be displayed or imported. You don't have Add and Customize Pages permissions required to perform this action) as shown:

But the confusing part is same user can add some other Web Parts like List View Web Parts without having this issue. Behind this behavior there is a logic to make these web part secured against the cross site scripting attacks.
Now we have a permission with the name Add and Customize Page.


This permission is not granted by default to the Contributor permission level. If we add this permission to the permission level users having contributor permission level will be able to add any web part to the page. This permission is given by default to Designer group. If these Web Parts are already added to the page and if the Contributor can only edit some of the properties.

There is another side of this story as well. If we dont want to give this permission to the contributors but still want that they should be able to add the web parts which were not allowed by default, we need to make a change in the Web.Config File. There is a new parameter introduced with the Safe Control entry with the name "Safe". This parameter decides which web parts are SAFE to be added by the people who dont have the Add and Customize Page permission. For any web part if we set this property to be False then the people not having Add and Customize Page permission will not be able to add this web part on the Web Part Page inspite they are the contributor.

I will change this property to Content by Query Web Part as below to false.

<SafeControl Assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.Publishing.WebControls" TypeName="ContentByQueryWebPart" Safe="false" AllowRemoteDesigner="True" SafeAgainstScript="True" />
Earlier when the Safe flag was set to True contributors were able to add this web part without any issue. Now if they try to add this web part they will get the following error (A Web Part of Web Form Control on this Page cannot be displayed or imported. The type is not registered as safe):
So if you want that contributors in your site should be able to add all the web parts we can change the value for this property.

Tuesday, 20 April 2010

Script to Create multiple SharePoint Site Collections

I had a requirment where we need to create multiple site collections and sites. It is very time consuming to create sites from UI one by one. To create sharepoint sites in bulk we can use a PowerShell script.
To achieve this we will pass a CSV file to the PowerShell script. The CSV file has the data in the following format:

Url                                               Owner             Language       Template
http://localhost/sites/demo1 domain\administrator 1033                STS#0
http://localhost/sites/demo2 domain\administrator 1033                STS#0
http://localhost/sites/demo3 domain\administrator 1033                STS#0

lets store this file in C: drive and then I will import this CSV file using the PowerShell command. Now we can execute a PowerShell script which will create bulk SharePoint sites based on the data in the CSV file.

$csvfile='c:\BulkSiteCreation.csv'
import-csv $csvfile | where {new-spsite -Url $_.Url -OwnerAlias $_.Owner -Language $_.Language -Template $_.Template}

Writing to ULS Logs using PowerShell in SharePoint 2010

With SharePoint 2010 the capability to write in ULS Logs has been significantly improved. We can now easily write our own custom message using SharePoint Object model or PowerShell:

Following PowerShell script can be used to write to ULS logs:
$diagSrc = [Microsoft.SharePoint.Administration.SPDiagnosticsServices]::Local
$diacategory = new-object Microsoft.SharePoint.Administration.SPDiagnosticsCategory(“My Category”,
[Microsoft.SharePoint.Administration.TraceSeverity]::Monitorable,
[Microsoft.SharePoint.Administration.EventSeverity]::Error )
$diagSrc.WriteTrace(0, $diacategory, [Microsoft.SharePoint.Administration.TraceSeverity]::Monitorable, “Write your log here” )

If we need to write using SharePoint Object Model following code can be used:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;

namespace CustomMessageToULSLog
{
    public class ULSLogMessage
    {
        public static void Main(string[] args)
        {
             
            SPDiagnosticsService diagSrc = SPDiagnosticsService.Local;
            diagSrc.WriteTrace( 0, 
                                                    new SPDiagnosticsCategory("Custom category",  TraceSeverity.Monitorable, EventSeverity.Error), 
                                                    TraceSeverity.Monitorable,
                                                    "Writing to the ULS log:  {0}",
                                                    new object[] { "My Custom Message!"});           
            
  
        }
    }
}

Friday, 9 April 2010

Using Multiple Search Results Core Web Part in a SharePoint Page

I was having a requirment where I need to customize the Search Result and I need to use two Search Core Results Web Parts. One will be displaying the normal results and one of the Web Part will display the results from only a specific scope. If we just put the scope in the Scope field this will not work. When the users will do the query both the search results will be going to show the same data. To make it working we have two options:

1. Either select the different query name for each web part. So we can have User Query in one Web Part and in another Web Part we can have Query 2 or so on.

2. If we want to use User Query then we can put the scope name in the Append Text To Query property.

This does not work as the two web parts that use the same query ID modify the same Query object and internally it passes the same query.

Wednesday, 7 April 2010

Creating New Sort Property in FAST Search for SharePoint 2010

FAST Search for SharePoint 2010 allows to add additional sorting fileds to sort the data in Search Results Core Web Part. With this we can add our own fields on which we want to sort the data. This capability is not available with the SharePoint 2010 search. This post will explain how to add a new field in the Search Action Links. Here are the steps to achieve this:

1. I added a column with the name Writer in one document library and populated with some data.
2. Initiate a crawl so that this column appears as a crawled property.
3. To find the list of all the crawled properties go to Central Administration and then go to your  FAST Query SSA. In the left hand side there is a menu item for FAST Search Administration


4. Now inside Crawled Property Category we have a category for SharePoint. Once the data is crawled Writer should be available as crawled property in this category:

5. Now this Crawled property needs to be associated to a Managed Property. We will create a new managed property for this.
6. Go Back and click on the Managed Property link and click on Click on Add a Managed Property.
7. Fill the required details and select the Type as Text. In the Mapping to Crawled properties select the ows_writer. There is a checkbox to make a property as Sort property. This property allows the managed property to act as sorting property. Make sure to check this box:


8. Once this is done this Managed property will be available to be added as Sorting property. But it does not appear by default. We need to add this explicitly in the sorting dropdown.
9. To do this go to the FAST Search Center and edit the Search Action Link Web Part. Here you will see all the managed properties which have the sorting enabled:

10. Select the managed property which we created and if you want you can make it default sorting property. Also we can change the label for this as it appears in the dropdown.
11. Once this is done the data in the core search results web part can be sorted using this property:

Monday, 5 April 2010

Disabling SharePoint Designer Workflows in SharePoint 2010

With SharePoint 2010 there is a new feature where we can disable the use of SharePoint designer workflows on the SharePoint Sites inside a Web Application. This feature prevents the use of any declartive workflows in the Web Application. This is done at the Web Application level so all the site collections inside that web application will not be able to create or use the workflows.
To disable the declarative workflows go to Central Administration site and select the Web Application. under General Setting there is a menu item for controlling the workflow for the Web Application:

Once you click on this following screen will be displayed:

Here we can disable the workflow. Once we do this, no workflows can be created in the SharePoint Site collections using the SharePoint Designer. Also we can not use the predefined workflows.

If we try to create a new workflow using SPD following error will be displayed stating "User-Defined Workflows have been disabled by the SharePoint Administrator. User Defined workflows will be unable to run."


Also once these workflows are disabled many predefined workflows are not available to be used in the site collections. Only Disposition and Three State Workflows are available to be used.

Related Posts with Thumbnails