Pages

Monday, April 25, 2011

It’s true that SharePoint team has made the SharePoint rich enough to be useful in any organization. But they have taken less care of developers (my personal opinion). Developing with SharePoint was really a nightmare in old days (in SharePoint 2007) and the situation has not been changed that much today. I reminisce the days back in 2008 when four members of our SharePoint team worked in a single SharePoint server by logging in remotely. When one developer needed to reset IIS he needed to to inform others either he may interrupt some others’ debugging session.

From that nightmare development experience of my first SharePoint project, I’ve come to a better place. Now I’ve Core I7, 8GB ram laptop. But I used to work in Virtual Machine till few months ago and I had got slower disk access in Virtual Machine. So compiling, debugging and deploying was relatively slow. I don’t want to install SharePoint in my laptops’ Windows 7 and I hope fewer (possibly fewest) people want to do so.

I’ve personally found developers who are coming to SharePoint Development from Asp.net, has got it difficult to get used to this environmental complexity. Anyway I’ve come to know about Virtual Hard Disk (VHD) solution few months ago and I’ve found it really a healthy approach. Let’s dig it deeper.

SharePoint Development in Virtual Machine

If you use Virtual Machine or any other virtual solution, you will have to realize that you will not the full processing power of your computer in SharePoint development. Even if in my Core I7 with 8GB ram, I get the development in Virtual Machine slower. If you do a lot of debugging and deployment you may loose your patience soon. However the real benefits include you can save virtual machine state. You can backup your virtual machine and restore.

SharePoint Development with Virtual Hard Disk (VHD)

Though I knew the concept of Virtual Hard Disk about a year about ago, I didn’t get interested about it till few months ago. Basically the concept if you will have a Hard Disk (virtual obviously) and you will mount that virtual disk as a drive in your computer. Then you will install OS in that drive and add that OS in boot menu in your computer. So you will have more than one operating system in your computer but the OS will be in Virtual Hard Disk (which is a .vhd file). I’m going to describe it in details:

Create and Initialize a Virtual Hard Disk

For your information, the following option for creating VHD file from “Computer Management” is only available in Windows Server 2008 R2 and Windows 7. I’ve not explored if the option shown below is available for other operating systems.

Open the “Computer Management” from Administrator tools and right click on the “Disk Management” and click “Create VHD” as shown below:

Figure 1: Create VHD option in disk management

Then in the New VHD window, enter appropriate value as shown below:

Figure 2: Create new VHD settings page

After that you will find a new disk is added as shown below:

Figure 3 New disk created for VHD

So you have found you new VHD as new disk but the disk need to initialized. To do right click on the new disk and click initialize as shown below:

Figure 4: Initialize Virtual Hard Disk

However when you’ll try to initialize the disk you will prompted for partition style. Its recommended MBR as shown below:

Figure 5: Create MBR partition in new VHD

After that you will find the disk (disk 1 in above figure) online. After that create a new volume in that virtual disk as shown below:

Figure 6: Create new sample volume in Virtual (but online) disk.

In the “New Sample Volume Wizard”, you can go with default settings and finally you will get a new drive in your computer which is virtual.

Mount a VHD and Install OS

Once you have your Virtual Hard Disk (VHD) ready you can try to install an OS in the VHD. To do so insert a Bootable CD/DVD in the CD/DVD-ROM and reboot your computer. To boot from CD/DVD make sure boot from CD/DVD enabled. I had tried to install Windows Server 2008 R2 in VHD. The process is described below:

First, let the OS to start from bootable disk. Then when the following window comes up, press Shift + F10 to bring command prompt.

Figure 7: Windows Server 2008 R2 installation window.

When the command prompt comes up (after press Shift + F10), type diskpart and press enter. And then type list volume and press enter to see all volumes available. Figure 8: Use diskpart command to list volumes.

You will find from “list volume” command that your drive letter is shifted by a letter (so, C becomes D, D becomes E and so on). Now type Select vdisk file=”VhdFilePath” as shown in the image below: Figure 9: Select VHD file command

Now you have selected the vhd file and you need to attach the file. To do so, run the command “attach vdisk” as shown below Figure 10: Attach Vdisk command

You have selected vdisk and attached it. Now close the diskpart by typing Exit and then close the command prompt by typing exit again.

Now you can click Next in the “Install Windows” wizard as shown in figure 7. As you have attached the vdisk in the system, Installer will show the vhd as an disk and you can then choose to install OS in that vhd disk.

When the Installation options come to choose the drive where to install OS, you can choose the VHD mounted disk (as shown in the image below). However you may get an warning saying “Windows Cannot be installed…” if you select the VHD for installing OS. Ignore the warning and install the OS in the vhd mounted disk. Figure 11: Select VHD disk to install OS

And when the installation will be finished, you will find your another OS is added in your boot menu.

So the final output is a file (VHD file) which is used for dual boot. You can copy the vhd file and attach it to another pc.

Attach an Existing VHD to boot option

Now say you have a vhd file and you need to attach the vhd file in boot option in your pc. You can do so with command. Fortunately, there’s GUI tools available to edit boot loader options. One such tool I’ve used is EasyBCD. I’ve shown below how to add a VHD file in boot menu.

Run EasyBCD and click “Add New Entry”.

From the bottom click “Virtual Disk” tab and then select the vhd file from disk.

Finally click “Add Entry” to add the entry in boot option.

The following image shows process in a glance:

Figure 12: Add VHD file in boot option with EasyBCD

Now when you will restart your pc, you will find the new newly added entry is in boot option. Be cautious while you edit your boot menu. Improper editing of boot menu may fail your booting system.

Conclusion

If you are working with SharePoint frequently (as I do), you need to care about every minutes you are loosing for working in Virtual Environment. Since few months ago I had used Virtual Environment in my powerful laptop (Core-i7, 8GB RAM). However, disk access in VM environment is slow and as Visual Studio performance is somehow related to disk access (as during build a lot of disk read/write access operations are performed) so finally performance was a major problem.

Now I’ve moved my work to VHD and I’ve two VHD files (one for SharePoint Foundation and another is for SharePoint Server). I’ve three OS in my boot options: Windows 7 (installed with my laptop), SharePoint Foundation and SharePoint Server. I can remove any boot option from my boot menu any time with EasyBCD. And most of all, with VHD option, I get the full power of my laptop. If you guys have doubt about VHD option, I’ll ask you to give VHD option a try and I do believe you will like it. You will have to like it. FYI, I’m not a marketing guy anyway so maybe it’s hard for me to convenience you.

Sunday, April 24, 2011

I’ve got the chance to test the Office 365 beta. After registering for the office 365, I’ve found it provides three services on the cloud as shown in the image below:

Exchange Online (Outlook in the image below)

Lync Online

SharePoint Online (Team site in the image below)

Figure 1: Three services provided by Office 365 (Beta).

So Office 365 is all about collaboration. How we collaborate in these days in enterprise environment?

Send mails

Text Chat, Voice Chat or Video conferencing etc.

Share Documents/files in collaboration

All these features are provided by Office 365. As usually, without Office 365, we need to setup Exchange locally in office, we need to setup some kind of communication software (like gtalk, skype etc). Also for collaboration or file sharing we need to use different custom solutions. However using Office 365, local installation and maintenance of these servers/solutions will not be necessary.

Also with the Microsoft Office Word, Excel, PowerPoint and OneNote in the cloud (with Office 365 beta), separate license of Microsoft Office is not required. SharePoint Online provides these Office services and also provides a public site as part of the Office 365 package.

Conclusion

So why Office 365? Once reason is cost. Local installation/maintenance of server/infrastructure is not required. No separate license of Microsoft Office is required. Another reason is manageability, Office 365 puts all these three services (Exchange Online, Lync Online and SharePoint Online) in a single place to manage. This is a great relief for Admin as he can manage any issues from a single point. Disaster recovery is another reason to move to cloud. Office 365 ensures maximum availability of the service.

Tuesday, April 5, 2011

In the last two posts (Part I and Part II), I had described on creating list definition/instance and how to attach the list definition and list instance with site definition. In this post I would go a bit farther and describe on site provisioning.

If you have followed my last two posts on this topic and developed a site definition and then created a site with that site definition, you will find the new site has nothing but the custom lists you have defined in the site definition. But in most cases we want a custom site definition alike Team Site definition, lets say, and then we want few more custom lists added to the team site definition. So in a sense we want to extend or inherit the built-in Team Site definition. So the requirement is:

Requirement 1:we want our custom site definition just like Team Site Definition

Requirement 2: but we want few more custom lists/libraries added.

Let’s discuss how to meet the requirements.

Site Provisioning

In SharePoint, you can hook the site creation (known as site provisioning) event.

Step 1 - Create Custom Site Provision Provider: You need to create a class which will inherit from abstract class “Microsoft.SharePoint.SPWebProvisioningProvider” . Then override the method Provision. In this Provision method you need to apply the template you want to use for your custom site definition. For your information, if you use your own site provision provider, then site will be crated with blank template and in this Provision method you need to explicitly apply the site template as shown below:

So basically in the above code snippet, I’m using Team Site Template whereas user selected the custom site template (developed by me). Few points to notice about Custom Site Provision Provider:

If you custom site provision provider then the site will be created with blank template

Since site will be created with blank template, you need to specify the template to use for site creation by using SPWeb.ApplyWebTemplate() in Proivision method of your custom Provision provider.

You can activate features in Provision method after applying web templates.

So in code snippet 1, I’ve applied team site template and it was my Reqirement 1. My second requirement was to create custom list/libraries on site creation. If you can remember from my second post on this series of article that I had developed two features: One for custom list definition and another for custom list instance. Since list definition feature is site collection scoped, we don’t need to activate this feature on site creation. Rather we need to activate the list creation feature on site creation so that the custom list gets created. Once list creation feature is activated in any site, the custom list associated with the feature will be created. So I’ve shown the modified version of code from Code Snippet1 to activate features:

So the provision provider shown in code snippet 2 is ready to go. Now we need to associate this provision provider with our custom site definition.

Step 2 - Associate custom site provision provider with site definition: To associate the provision provider with site definition, open the webtemp_SiteDefinitionName file and add two properties ProvisionAssembly and ProvisionClass as shown below:

Figure 1: Specify the provision attributes in Site Template file.

As shown in the Figure 1, the ProvisionAssembly value is set to a Visual Studio token ($SharePoint.Project.AssemblyFullName$) which will be replace with Project namespace by Visual Studio. However if you are using non-SharePoint project template in Visual Studio then you can use the full namespace in ProvisionAssembly instead of the token. The ProvisionClass is the full name of the custom provision provider. The full xml is give below so that you can easily copy/paste.

Now you are done. You can now deploy the SharePoint solution and try to create a new site with the custom site definition. You can check if your custom provision provider is used by attaching the debugger with w3wp and setting a breakpoint in Provision method.

Conclusion

I’m not sure if this is the last post of this series but if I get interesting topics later, I’m hoping to write another post.

Monday, April 4, 2011

In the first part of this series of posts I had described on how to develop list definition and list instance. In this post I’ll explain how to use those list definition and list instance with site definition so that the list item is created on new site creation. Just to recall, in the first post, I had got two features that I need to active on site creation.

Now you have your list definition and list instance ready (with two features). Now you need to create a site definition. To create a site definition to an existing SharePoint Project you need to install Community Kit for SharePoint: Development Tools edition visual studio extension.

Step1: Add the site definition in the Project: Click Add new item and from the Add new item dialog click “Blank Site Definition (CKSDev)” as shown below:

Once you have added the Blank Site Definition, you will find three files are added in the project.

Step 2: Modify webtemp file: You can find a file named like webtemp_sitedefinition in the site template folder. This file defines the template names, title, groups etc. Open the file and modify the description and displaycategories. However, don’t change the template name in the editor as the template name in this file related to template folder in the solution explorer as shown below:

Figure 2: Template file editing

Step 3: Modify Onet.xml file: One of the file is Onet.xml which is the key player in customization. If you can remember from part I of this series of post, that we had two features: one was for list definition scoped at site level and another was for list instance scoped at web level. Open the Onet.xml file and add the list definition and list instance feature IDs in SiteFeatures and WebFeatures section correspondingly as shown below:

Figure 3: Features to be activated defined in Site Definition

And you are done! Now build the solution and deploy. Once deployment done, try to create a site with the new site template, if everything works out then in the new site you will find your list created.

Your client wants to have a site definition that will add a site template in the ‘create web site’ list and when user will create a site based on the site definition, a list will be created and few features will be activated. In this post I’ll focus on creating a list definition and list instance.

Create list definition and List Instance

Step 1: Add List Definition and List Instance to the project: To create a list definition along with list instance add a List Definition item in SharePoint Project as shown below. For easy understanding, you can put Def at the end of the list definition name.

Figure 1: Create List Definition item

Later you’ll be prompted for list name, list definition type and ‘if a list instance will be created’ option as shown below. You may need to modify the list definition name, and list definition type. Also make sure the ‘Add a list instance for this list definition’ is selected as shown below.

Figure 2: List Definition Creation dialog

Step 2: Set List Instance Name and Title:After the list definition and list instance are added to the project, you will find the list instance name is generated automatically which you want to rename as shown below:

Figure 3: Rename auto-generated list instance name

Then focus on modifying the List Instance elements.xml file. At least modify the list title and URL as shown below:

Figure 4: Rename list instance title and url in elements.xml file of the list instance.

Now you have added the list definition and list instance and your next step is to define the list

Step 3: Define Template Type: Now you have added the list definition and list instance. First of all make sure you have put a type id for list definition and used that type id in list instance as shown below. I’ve set the template type in the left file (list definition) as (Type=10001) and the same type is used in the right file (list instance) as shown below:

Step 4: Add fields in the list definition: Now you are ready to add fields to the list definition. For this open the Schema.xml file under list definition folder and move the position between <Fields></Fields> as shown below:

Figure 6: Add Fields in list definition

So you are ready to add fields but it’ll be tough to add all fields just by typing manually. There’s trick I use often:

Create a test list with the required fields

Save the list as template

Download the list template from template gallery.

Rename the template file extension from .stp to .cab

Open the cab file and extract the Manifest.xml file.

Finally I take the field definitions from the Manifest.xml file

Step 5: Add fields to default view: In this step, you will add the fields to the default view (or any other view you want). If you take a look at the schema.xml file you will find more than one views are defined in the schema file. However, the view with DefaultView=”True” is the default view. Normally the view with BaseViewID 1 is the default view as shown below:

Figure 7: Default View with BaseViewID property value set to 1

So you have found the default view and now you need to add the field reference in the default view. As shown below, you can either user GUID or Field Name for referencing a field in ViewFields:

Figure 8: Add Field Ref in ViewField either by Field Name or ID

Though you can use either Field Name or ID for referencing a field in ViewFields, I prefer ID as the name can be changed/modified or XML encoded.

Step 6: Associate List definition and list instance with Two Features: Now you have two elements files: One is for list definition and another one is for list instance. With SharePoint architecture in mind, we need to activate the list definition in Site collection. Whereas the list instance needs to be created in individual web. So add two features and associate the elements.xml (FYI, elements.xml file can be associated with features) with features.

We need to add a feature with site collection scope, and need to associate the list definition with that feature. In my case the feature ID is 574b2a16-b01d-4e30-97ed-d1c4a5aa37ea. You are not done yet with the list instance, you need to take the feature id (in which the list definition is attached) and put the value in List Instance elements.xml file as shown below: Figure 9: List Instance Elements.xml file with list definition Feature ID

We need to add another feature with web scope and need to associate the list instance with the feature

So after this steps we get two final outputs (i.e., two features) that will be used in site definition. So collect the two feature IDs (you can get the feature ID by selecting and then opening the properties window). In my case the List Definition feature ID was 574b2a16-b01d-4e30-97ed-d1c4a5aa37ea and List Instance Feature ID was 161c4ebd-97b7-4dff-9734-c930434d3e95.

Conclusion

Until now you have developed one list definition, one list instance and two features: one for list definition and one for list instance. in the next post I’ll explain how to staple these list definition/instance with site definition.