Archive

Archive for December, 2009

Develop, Deploy and Debug Sandboxed Solutions

December 18th, 2009 4 comments

Sandboxed solution in SharePoint 2010 is a new way of deployment for rapid development. You can deploy your solutions on site collections without resetting the farm. Sandboxed solutions are per site collection. You can create them like the normal farm solutions. You can see the detailed information about sandbox solutions here.

Develop SandBoxed Solution

 In Visual studio 2010 there is a lot of support for SharePoint projects. Whenever you start a new SharePoint project (except a few options) it will ask you about the solution type in second window. By default sandboxed solution is selected as solution type.

Select Deployment type

You can also change the deployment type at any time from the project properties window.

Change Solution Deployment type

In a SharePoint solution you can have assemblies, features, Web Parts, list definitions and feature receivers. Now if you want to add a Web Part in this solution, right click on the solution and select add new item.

Add new item

Select Web Part from the available option. In Sandboxed solutions you cannot use Visual Web Part. Actually from sandboxed solution you can deploy files to web front-end server. Visual web part deploys visual files to server. So you can use the simple Web Part from the option. If you select Visual Web part, you will notice that sandboxed solution option will be grayed-out in next screen, where you define deployment type.

Select Web Part

Now you can start writing your code for web part. I have added a snap-shot of sample code.

Code

It’s a simple piece of code, accessing a list from the site collection and displaying items in a ListBox control. In sandboxed solutions you can access all the classes under SPSite, SPWeb, SPList, and SPListItem. Sandboxed solutions deploy as partial-trust solutions, so there are some limitations. You cannot use classes other than mention above. For example you cannot use code for run with elevated privileges block. If you try to use classes outside the scope of sandboxed solution you won’t get IntelliSense from Visual Studio. If use SPSecurity.RunWithElevatedPrivileges it will compile without any error message. It is because of the fact that visual studio compile against the full API of the SharePoint. Visual studio helps to write code specific for sandboxed solution by providing proper IntelliSense for available classes. But if you use code from a full-trust solution, there is no way to detect error in visual studio. You can only see exception when this code execute in sandboxed process. The exception thrown is “Could not load type ‘CodeToRunElevated’.

Use SPSecurity Error

When your build is successful, you can create a wsp file. In visual studio 2010, create a wsp is very simple. Previously it was another painful task to create wsp file. You had to use different ways to create a cab file and then rename it with extension wsp.  Now you can right click on the solution and select ‘Package’ option. It will create a wsp file for current solution in bin/Debug folder.

Create wsp solution
Deploy Sandboxed solutions
Deployment of sandboxed solution is very simple and rapid. You just have to upload your solution in a library name solutions. Every site collection in SharePoint 2010 has a solutions library. You can see more details about solution library here. Solutions library is a SharePoint list. When you upload your solution it will prompt to activate it.  If you like to upload a solution, better way to open the solution files in visual studio and then after the changes build and create a new solution. Now deactivate old solution from the solutions library and upload new solution. Finally activate it. Your solution is now deployed including the web part. Here you can also see that how you can use your custom web part in SharePoint pages. Click here

Debug Sandboxed solution
We know that SharePoint sites runs under the IIS worker process w3wp.exe. In order to debug SharePoint sites we attach our code to w3wp.exe process. But sandboxed solutions run under a different process Sandboxed worker process (SPUCWorkerProcess.exe).  so if you want to debug your code in sandbox solution you have to attach your code to SPUCWorkerProcess.exe and if you like to debug rest of the page then you have to attach it to w3wp.exe process.

Task manager view

I hope it will be helpful, I will try to explore more in coming days and will share again.

Solutions Library – SharePoint 2010

December 17th, 2009 53 comments

One of the salient features in SharePoint 2010 is sandboxed solution. You can see the detailed introduction to sandboxed solutions in my other blog. Every site collection in SharePoint 2010 has a library with name Solutions. You can upload your sandboxed solutions in this library. This is a simple SharePoint list. In order to access it you have to open site settings page. You can select Site Settings option from site actions menu.
From site settings page, there is a link for Solutions library under Galleries section.Site Settings Page

Solution library displays the list of solutions, their status and the resource usage as well. It also displays resource quota information for server resources, also current usage and average usage. You can also activate and deactivate solutions. In solutions library you can upload your solutions. For this you can select upload solution option from the ribbon.

Solutions Library

When you click on upload solution, it will open a window like this.

Upload Solution

This window is saying upload document, I don’t know why. May be it’s just a beta version. It should say upload solution, and solution file could be pre-selected in file type filter. You can browse your solution (wsp) file. You can activate the solution straight away after the upload or at any other time.

Activate Solution

You can remove any solution from the library. But this solution should be deactivated first. You can also upgrade any solution but the condition is same, it should be deactivated first. In order to upgrade the solution your solution id should be the same. Whenever you upgrade a solution, it will deactivate the old version and activate the new version.  If you try to upgrade any activated solution, you will see error windows like this.

Upload same solution - Error

In solutions library, you can upload any type of file. But the ribbon is context sensitive. Activate, Deactivate and upgrade buttons could be enabled only for wsp files.
I hope it will be informative about solutions library.

Create WebPart page and use custom WebParts – SharePoint 2010

December 16th, 2009 Comments off

This topic is probably for new users of SharePoint. It is a very simple task for old SharePoint users to create a web part page and use a custom web part. In this topic we will see step by step that how we can create a web part page in a publishing site using SharePoint 2010, and how we can use web parts in the page.
There are two straight forward ways to create a web part page in publishing site. First you can click on site actions menu and then select New Page option from there.

New Page

When you click on New Page option, it will open an AJAX window, where you can define the name of page.

Create New Page - Name

It will create a basic page. From the ribbon you can select Page Layout option. It will open a drop down to select page layouts from the existing layout types. You can select Blank Web Part page from here. It will change the page layout to blank web part page layout. You can also create your custom page layouts and can use here to create new pages.

Select WebPart page layout

Second way to create a web part page is to select ‘site actions’ and then select view all site content. Then select the create option, it will open different items to create like custom list, different page types, libraries. From there you can select web part page.

Create options window

Or you can also select page in filter by option. And then can select web part page. All the above options will create the same web part page.

Create - Filter by Page

On this layout there are different web part zones, where you can place your web parts. When you select Add a web part from any available zone, it will open the list of available web parts in different categories on top of the page. First option is for list and libraries. Here you can see all the existing list and libraries.

Select list in webpart

For the header zone I have selected an existing list Regions as a web part. It will look like this.

List view in web part

Now if you have created your own web part and added through some solution to the web application, then you can also use your custom web part in this page. For this click on Add Web Part option and then select the custom category for web parts. From here you can select your existing web parts for the page.

Select Custom webpart for page

It is a very basic option but hope it will help to the new users of SharePoint.

Have Fun.

Sandboxed Solutions in SharePoint 2010

December 14th, 2009 2 comments

SharePoint 2010 came with lots of new features and ways for developers and users. Sandboxed solution is one new way of deploying solutions. You can also have the solutions as you have in SharePoint 2007, but those solutions will be called farm solutions. Sandboxed solution is per site collection. Sandboxed solution’s deployment is different than normal solutions. Every site collection in SharePoint 2010 has a library for sandbox solutions. You simply need to upload your solution (wsp) to this library. And then activate the solution. So no server reset is required.
Sandboxed solution doesn’t make server reset, so you can do as much deployments as you want. It is very convenient from developer’s point of view. But at the same time there are some limitations for sandboxed solutions. Farm solutions run with full trust, whereas sandbox solutions mark as partially trusted solution. The major difference is the way of deployment. You can run the same solution under full-trust, but then you need to deploy it as a farm solution. As you do in SharePoint 2007.
The limitations for the sandboxed solution is due to the factor that it should not be a performance hinder for farm and application. These are the major limitations I found so far in sandboxed solutions.

  • You cannot run your code with elevated permissions in sandboxed solution
  • You cannot use Visual web part template for sandboxed solution. Because sandbox solution cannot deploy files to web front end.
  • You cannot access internet to make web service calls directly
  • You cannot access hard drive to read/write files
  • you can’t access code that is not marked to allow partially trusted callers
  • you cannot deploy assemblies to GAC

It seems that in sandboxed solutions’ you cannot do much but still you can. In sandbox solution you can access all the classes under SPSite, SPWeb, SPList, and SPListItem. You can create Web Parts, list definitions and instances, content types and fields, modules, declarative workflows, and event receivers. You can read and write to lists and libraries within same site collection. Sandboxed solutions provide enough functionality to build most of the applications. The best thing is rapid deployment and no server reset.
Being a developer you would definitely want to go out of the limited scope of sandboxed solutions, like communicate with a database or web service. According to SharePoint team the best way to reach out of the sandbox is by using the Business Connectivity Services (BCS) to create an external content type. You can then read and write to the data source from the sandboxed solution. Another, more advanced, way to reach outside the sandbox is to create a class that runs in a full-trust process outside the sandboxed worker process to proxy calls. This proxy class is deployed as a farm solution and is callable from the sandboxed solution.
Sandboxed solution runs under a different process, farm solutions run under IIS worker process (w3wp.exe). But sandboxed solution runs under the sandbox worker process SPUCWorkerProcess.exe.
In sandboxed solutions library, you can activate and deactivate solutions. You can also remove solution from the library, but solution should be in deactivated state. You can also upgrade a sandboxed solution. To upgrade a solution, you need to create a .wsp file that has a new file name but the same solution ID. The easiest way is to use Visual Studio 2010 for it. Open the same solution and after the changes, give the package a new name using package designer. When you try to upload new solution, it will detect the solution with same id and ask for upgrade. After you upgrade, you will see it activated new version and deactivated old solution.

Sandboxed solution is a great enhancement for developers and also for administrators. Now all the solutions deployment is not the responsibility of the farm administrators. Site collection administrator can deploy, manage and monitor sandboxed solutions for their site collections. Developers can test functionality without disturbing the whole farm. They can deploy the same solution with full trust later, when they have confidence in the new functionality or at convenient time. Isn’t that a great news.

Cheers

Issues notification from Health Analyzer – SharePoint 2010

December 3rd, 2009 Comments off

In my previous post I discussed something about Health analyzer in SharePoint 2010. When health analyzer finds some issues against the pre-defined rules. It shows notifications on the Central Admin screen. This notification bar will look like this. If there is any error then this bar color will be Red, if these are just warnings then it will be yellow.

Red Notification for errors

Errors notification in red bar.

Yellow Notification for warnings

Warnings notification in yellow bar.

When you click on view these issues, it will take you to the health report page. From there you can see the details of each issue and can edit the item as well. If you think that these issues are coming against unnecessary problem. Then you can also change the rule definitions by disabling or removing it from the Health Analyzer list. For this you can read my previous post about Health Analyzer.
There could be unnecessary issue notifications, like I’m running SharePoint 2010 on my hp laptop and it was giving me low disk space error for recovery disk. So I just remove this error from the list.

Health Report

And here you can see the screenshot of the details page when you click on any of the issue. If you think you have fixed the issue, then you can reanalyze it as well to remove this error from this report. 

Review problems and solutions

Here you can also change the severity of the item. It will give you all the details about the issue, server name where this issue occurred. It will also tell you failing service and some description for the item. Now you may like to remove this from rule definition. On this screen you can see the category name and then you can find this rule from the rule definitions list under this category. The interest section is remedy, where it will gives you some idea about the problem and solution for it. Isn’t that amazing thing from Microsoft?

Have fun.

Health Analyzer in SharePoint 2010

December 3rd, 2009 Comments off

One of the amazing features in SharePoint 2010 is Health analyzer. Health analyzer is working through the timer jobs and collect data from these jobs. This data is saved in logging database and logging folder. These health analyzing jobs are configurable. You can reschedule, enable, disable, or run immediately.
By default these jobs are running against some pre-defined rules. These rules are in belongs to different categories like Security, Performance, Configuration, and Availability. If you go in Central Administration and click on Monitoring.

Monitoring

 On monitoring page there are two options under Health Analyzer section. ‘Review problems and solutions’ is to take you to a page displaying all the current issues and ‘Review Rule definitions’ will open the page with existing rules.
On this page you can see that when these rules are schedule to analyze, enabled or disabled, and if repair automatically is selected or not. From this screen you can also remove any existing rules.

Health Analyzer Rule Definitions

When you click on any item it open a dialog window with the properties of the rule. On this dialog you can change settings for selected rule.
Selected Rule

Here you can change the Scope for rule. In Scope you define the server to run the timer job. It could be just one server or can be set to ‘All Servers’ in farm. Then you can change the schedule for rule. Then you can enable or disable the rule and also can set the property for Repair Automatically. If you set this property to yes, then SharePoint 2010 will try to resolve the problem for you. I don’t really know that SharePoint 2010 can resolve all the problems. But you can give it a try for basic things. As we have these rule definitions as a SharePoint list, so version is actually telling the version of the list item.

Create New web application in SharePoint 2010 – Part 2

December 2nd, 2009 Comments off

Continue from part – 1, if we want to use windows authentication we can select this option on this part of screen. SharePoint team recommends Negotiate (Kerberos or NTLM). If you want to enable form base authentication then you can select the option to enable ASP .Net Membership and Role Provider.

Configure Authentication

If you are using ‘Custom Based Authentication’ you can define a custom login page. You need to give the url of login. Public URL part is same as SharePoint 2007. You can extend your web application later for other zones. For example if you want to extend your site for internet access, you can extend your site using internet zone.

Configure URL

In this section you can configure application pool and security account for application pool. If you are creating first application or if you have not registered any managed account. Then before using configurable account you need to register managed account from the given link. In my case this is the first web application, so I will register a managed account.

Configure Application Pool

Next section is the same as in SharePoint 2007 to configure content database.

Configure Database

Now there is a new option for failover database support. You can find more details here (Failover Database Support).

In next screen you can add remove service application connections for your web application.

Service Application Connections

Now in SharePoint 2010, services concept has been shifted from Share Services Provider (SSP) to the service application. You can read this article from Andrew Connell for more details. By default all web applications are associated with the farm’s Default group of service application connections, although you can change this setting. Here you can see my article that how you can create a custom set of service application connections.

Now the last section is about Costumer Experience Improvement Program.

Customer Experience Improvement Program

This is the optional field. If you opt-in to the Customer Experience improvement Program, anonymous data about how you use SharePoint 2010 are uploaded to Microsoft occasionally in the background.

Cheers

Create New web application in SharePoint 2010 – Part 1

December 2nd, 2009 1 comment

This article is for the beginners in SharePoint 2010, if you are thinking to create a new web application in SharePoint 2010, here is the step by step description of all the steps. If you have already done this using SharePoint 2007, it’s not much difference except a few things.
Open SharePoint 2010 central admin, you can open it directly from the URL if you remember that or from the start menu under the SharePoint 2010 Technologies tab. It will open like this.

Central Admin

If you have upgraded from SharePoint 2007 you will see new user interface here. It’s almost the same but new color schemes and a lot of AJAX. One thing is also to notice that now ribbon is everywhere. You will see ribbon on all the pages. You can see in future posts that you can hide it as well. To create new web application click on the ‘Manage Web Application’ link under ‘Application Management’.

Manage Web Applications

Here you can see the ribbon on top of the page. This page will display all the web applications you have already created. On top left there is a option for ‘New’ on the ribbon. You need to click it to open create new web application dialog. When you click on new, you will see AJAX working on SharePoint 2010. One thing you must remember that you need a really fast machine with plenty of RAM (memory) on it. As recommended by SharePoint 2010 team, you need at least 4GB RAM. If you are running on less than that it will be really slow. Here is the AJAX screen.

AJAX screen

After a few seconds you can see this ‘Create New Web Application’ screen. It will be a pop up, not like the new page loading in the same window of central admin. I think it’s just to give SharePoint 2010 new look.

First View - Create New Web Application

Come to the point, first thing to configure is authentication type. Here SharePoint 2010 has introduced a new authentication type. ‘Claims Based Authentication’. I have a small article on the introduction to Claims Based Authentication. From there you can get some idea that what is new here. If you are happy with classic authentication then you can use ‘Classic Mode Authentication’. It will work the same as in SharePoint 2007.
After that it’s the same old stuff, for IIS web site. I will recommend you to use new IIS web site. You can change the name and also you can change the port. You can also define any host header. For example if you like to run your site on a URL like http://mysharepoint2010site/ , you can give this value in host header. By default it create web site in wwwroot directory and use port number as site directory name. You can also change it. Then you can select anonymous access or SSL.

Continue on Part – 2

Service Application Connections in SharePoint 2010

December 1st, 2009 1 comment

SharePoint 2010 has introduced service application architecture. When you create a service application in SharePoint 2010, a service application connection is created. A service application connection is also referred to as an application proxy. A service application connection associates the service application to Web applications via membership in a service application connection group.
When you add a new service application connection, it is added to the default group of service application connection. But you can change the default membership. If you are using PowerShell instead of by using Central administration, the new service application does not automatically become a member of the default group unless the -default parameter is supplied.
Service application group settings are highly customizable. When you create a new web application, it is associated to the default group by default. But you can change these settings. You can create custom service application groups and you can also add remove services from default service application groups.

Add/remove service application connections

In order to change the service application connections/associations. Open ‘Central Administration’, make sure current user is a member of Farm administrators group. Click on the ‘Application Management’. It will open like this.

Applications

Click on ‘configure service application associations’ under Service applications section.

Application associations

Now on this screen you can change the service application associations/connections for any web application or you can also add/remove service application connections for default group. Now if you want to change the service application connections for any web application then click on the web application name. It will open a dialog with the list of service application connections.

Configure Service Application Associations

By default when you create a new web application, SharePoint 2010 associates default service application connections group with new web applications. So when you open it first time, you will see default selected on top drop down box and it will have all the service application connections selected and also in disable mode. You cannot add/remove service application connections from default group using this screen. In order to add/remove connections, you need to change the top drop down value to custom and then you can select connections you want for the web application. Click ok and your new settings are ready. Your application associations screen will change like this.

Application Associations Changed

You can also change the service application associations for default group, for this click on the default link. And then select or unselect pre-selected options. Click ok and now default group is changed. So next time when you create new web application SharePoint 2010 will associate this default service application connections group to new web applications.

Configure Default Group

Cheers