Thursday, May 31, 2012

Unable to find type [Microsoft.SharePoint.Administration.SPWebService]: make sure that the assembly containing this type is loaded

I got this error while trying to enable developer dashboard using PowerShell command. The error message I got is "Unable to find type  [Microsoft.SharePoint.Administration.SPWebService]: make sure that the assembly containing this type is loaded".

Solution:
To over come this issue I am explanning what I did:
I opened my powershell and then navigate to c:\users\administrator and from this I run the below command:

Tuesday, May 29, 2012

SPMonitoredScope in SharePoint 2010

Before reading this article, it is better to have some knowledge on Developer Dashboard which is a very useful feature for SharePoint Developers. By using Developer Dashboard you will able to see performance of SharePoint 2010 page. It will show details about execution time and some valuable information.

But suppose you have written a piece of code and you want to see the execution time for the custom code section, then SPMonitoredScope class will help us. If we will use this class then we will able to see the execution time in the Developer dashboard.

Monday, May 28, 2012

ContentIterator Class in SharePoint 2010

In this article we will discuss about ContentIterator class which is introduced in SharePoint 2010 object model. Also you can check some SharePoint 2010 object model articles here.

- This class is introduced in SharePoint 2010 server object model.

- This class help us to manage large list in SharePoint 2010, also you can check another way to manage list using Query throttling. Whenever size of list increases we should optimize such a way that it will not affect performance of the site.

Monday, May 21, 2012

Get current zone in SharePoint 2010

In this article we will discuss how to know about the zone of the incoming request.

Also you can check out some posts on:

- SPLimitedWebPartManager Class in SharePoint 2010

- Differences Between Sandboxed and Farm Solutions in SharePoint 2010

- Create a sequential workflow using Visual studio 2010 in SharePoint 2010

To know the zone of a request we can use the SPContext.Current.Site.Zone class. You can check some an Article on SPContex class in SharePoint 2010. This returns an enum of SPUrlZone which represents wether its a Default zone, Intranet Zone, Internet Zone, Custom Zone or Extranet Zone.

This is presented in Microsoft.SharePoint.Administration namespace and also this is available in Sandboxed solution.

Here is a code sample:

using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

                    string Zone = string.Empty;
                    if (SPContext.Current.Site.Zone == SPUrlZone.Extranet)
                    {
                        Zone = "Extranet";
                    }
                    else if (SPContext.Current.Site.Zone == SPUrlZone.Internet)
                    {
                        Zone = "Internet";
                    }
                    else if (SPContext.Current.Site.Zone == SPUrlZone.Intranet)
                    {
                        Zone = "Intranet";
                    }
                    else if (SPContext.Current.Site.Zone == SPUrlZone.Custom)
                    {
                        Zone = "Custom";
                    }
                    else if (SPContext.Current.Site.Zone == SPUrlZone.Default)
                    {
                        Zone = "Default";
                    }

The solution cannot be removed when a job is scheduled or running

We discuss about the error "The solution cannot be removed when a job is scheduled or running". Also you can check some forum topics here and also you can see some errors that has been solved.

Usually If you are trying to Remove a solution (which is nothing but a .wsp file) by using PowerShell command like Remove-SPSolution –Identity mywspfilename.wsp. But before this we need to execute the UnInstall command which is like below:

Uninstall-SPSolution –Identity mywspfilename.wsp –WebApplication https://WebApplication URL

The solution is very simple. If you run the Uninstall command then in the background its doing something. So the approach is give sometime between the UnInstall command and the Remove command.

Else sometimes also you will get the errors like: "Cannot uninstall the languagepack 0 because it is not deployed".

Also sometimes you will get the error: "The solution wspfilename.wsp has been deployed in the farm. Please retract the deployment before removing the solution. You can also use the -override parameter to forceible remove the solution, but you will not be able to  retract the solution deployment "

Friday, May 18, 2012

Limitations of Sandboxed Solutions in SharePoint 2010

In this article we will discuss what are the limitations of Sandboxed solutions. You can check my last article on What you can do with Sandboxed Solutions?

- Since Sandboxed solutions are site collection specific, so you can not access data from other site collections. You can only access resources within the same site collection.

- You can not use SPSecurity.RunWithElevatedPrivileges method in case of Sandboxed solution.

- Executing code within Sandboxed solution causes a little performance overhead. Also Sandbox worker processes are terminated if they run for more than 30 seconds.

- Logging functionality is unavailable within the sandbox environment. Sandboxed solutions cannot write entries to the Windows Event log or the Unified Logging Service (ULS) trace log.

- You cannot read configuration settings from or write configuration settings to the Web.config file.

- You can store and retrieve settings in the SPWeb.AllProperties hash table, but you cannot use property bags at any level of the SharePoint hierarchy.

- You cannot read or write settings to the hierarchical object store, because you do not have access to an SPWebApplication object or an SPFarm object.

- You can read or write settings to a SharePoint list within the same site collection not to other site collection.

- In case of deployment you can not deploy any files to the server file system in Sandboxed solutions.

You can also check my article on Create event receiver in Sandboxed solution is SharePoint.

Wednesday, May 9, 2012

This solution contains no resources scoped for a web application and can not be deployed to a particular web application

Recently when I was trying to deploy an event receiver to my SharePoint site using PowerShell I got the error as:

"This solution contains no resources scoped for a web application and can not be deployed to a particular web application".

Also you can check out my previous posts on:

Reusable Approval workflow in SharePoint designer 2010

Mobile apps for SharePoint 2013

- Create Site in SharePoint Online

Install-SPSolution –Identity MySolution.wsp –WebApplication http://mywebapplication -GACDeployment

But I got the error as This solution contains no resources scoped for a web application and can not be deployed to a particular web application. Sometime also you will get error message as "The Project Item EventReceiver1 cannot be deployed through a Feature with Farm scope".

There can be several reason but you can try some solution like below:

Solution-1: 
Right click on the project and press F4. This will open the project properties window. From there Select the Assembly Deployment type From GlobalAssemblyCache to Web Application as shown in the figure below.

Solution-2:
You can also try the below commands by defining local like:
Install-SPSolution -Identity MySolution.wsp -local -GACDeployment

Solution-3:
Also you can try below command:
Install-SPSolution –Identity MyHpIndigoEventReceiver.wsp -GACDeployment

Also you can check some PowerShell articles here.

Change page layout programmatically SharePoint 2010

In this article we will discuss how to change page layout programmatically in SharePoint 2010. You can also check an article on how to Create Page Layout using SharePoint Designer 2010.

Here we will discuss how to change the page layout at the time of site creation. So for this we have written one event receiver. You can see an article on how to create event receiver using Visual Studio 2010 in SharePoint 2010.

Since we want to change the layout after the site creation, so we need to write our code in the WebProvisioned event as shown below.

public override void WebProvisioned(SPWebEventProperties properties)
        {          
            try
            {
                if (PublishingWeb.IsPublishingWeb(properties.Web))
                {
                    PublishingWeb curPubWeb = PublishingWeb.GetPublishingWeb(properties.Web);

                    foreach (PageLayout curLayout in curPubWeb.GetAvailablePageLayouts())
                    {
                        if (curLayout.Name == "OurCustomPageLayOutName.aspx")
                        {
                            foreach (PublishingPage curPage in curPubWeb.GetPublishingPages())
                            {
                                curPage.CheckOut();
                                curPage.Layout = curLayout;
                                curPage.Update();
                                curPage.CheckIn("");
                            }
                            break;
                        }

                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
}

Once you will deploy the event receiver, try creating a web site and you will see the layout must be changed to OurCustomPageLayOutName.aspx layout.

Thursday, May 3, 2012

Twitter updates in SharePoint 2010

In this article we will discuss how to show twitter updates in our SharePoint 2010 site.

For this first go to https://twitter.com/about/resources/widgets/widget_profile and in the customize section Give Twitter user name as well as you can also set preference like wether to include scroll or not, number of tweets to show etc.

Also you can set the appearance like background color, link color, tweets text color etc. Also you can set dimensions like width height etc.

Once set the above details then click on finish and grab code like below figure.

Tuesday, May 1, 2012

SharePoint Search through Server Object Model 2010

In this article we will discuss how we can do SharePoint 2010 enterprise search through SharePoint 2010 object model. Also you can check my last article on FAST Search Server 2010 SharePoint 2010 .

SharePoint Search is very much important for enterprises. We will see how we can do free text search trrough SharePoint 2010 object model. There are two very much important classes for SharePoint 2010 object model to use:

1. FullTextSqlQuery: This issues full-text SQL syntax queries to the search provider.

2. KeywordQuery: This issues keyword syntax queries.

Below is a sample code for search: