Monday, 30 April 2012

SharePoint 2010 : CAML Designer Beta Version Launched

CAML lovers….finally much awaited CAML Designer beta version has been launched….it is SharePoint 2010 version of CAML Builder with lots of improvements, new functionalities…you will love it.

Having SharePoint to Linq provider feature in SharePoint 2010 and its ability to generate CAML, I doubted future of CAML builder. But after seeing the CAML Designer beta version and its supported functionalities, now I am left with no doubts that it will be a big hit again. Three cheers for Karine Bosch and Andy Van Steenbergen for their efforts towards SharePoint community.

Some of the eye catching improvements than its predecessor:
  • UI support for ViewFields
  • UI support for QueryOptions – remember the difficulties querying folders…you are blessed now
  • It generate code snippets for different object models including list.asmx web service and REST.
  • Improved new look
Download the CAML Designer beta version from http://sharepoint.biwug.be/Pages/Downloads.aspx to explore it by yourself.

Sunday, 29 April 2012

SharePoint: Create List Template/ List Definition - Part 2


List Template blog series:
Part 2 : Basics of List Templates/ List Definitions – Intelligent approach (Currently reading)

This approach does not need you to write any xml or code, instead it uses some code generation technique. If you are familiar with MOSS 2007, then you must be aware of SharePoint Solution Generator or SharePoint Manager 2007 which can be used to generate list library xml files. In SharePoint 2010, there is more polished way to do same which I am going to explain in this post. Note that I have not discovered this approach. Many people are using it and have blogged about it. It is like I am just showcasing it over here again.

Below are the high level steps:
  • Create list/ library and customize it according to the requirements through browser.
  • Create site template of the site in which list is created using Save as Site Template feature.
  • Download the site template wsp from Solution gallery.
  • Import the downloaded wsps into Visual Studio 2010 using Import SharePoint Solution Package project which will generate the required xml files for list/ library.

I prefer and recommend creating list/ libraries using traditional approach. However, you can use this method for creating complex list templates for saving time. 

To demonstrate, this time we will create a Loan Requests custom library template. This template will be associated with custom Loan Request content type having custom document template.

Steps:

1.  Create a document as shown in figure 1 and name it as Loan Request Template.

Figure 1 : Loan Request Document

2.  Create Loan Type, Loan Amount and Loan Reason site columns through browser in Site Column gallery with the details given in Table 1.

Site Column
Type
Required
Description
Group
Any other details
Loan Amount
Currency
Yes
Enter the loan amount required.
SharePoint 2010 Custom Development
Currency Format : Rs. (India)
Loan Reason
Single line of text
Yes
Enter the reason for which loan is required.
SharePoint 2010 Custom Development

Loan Type
Choice
Yes
Select the loan type.
SharePoint 2010 Custom Development
Choices:
Educational Loan
Personal Loan
Furniture Loan
Home Loan

3.  Create the Loan Request Content type as shown in figure 2.

Figure 2 : Create Loan Request content type

4.  Add the site columns created in step 2 to Loan Request content type.
5.  Click on Advanced Settings link present in Settings section.

Figure 3: Advanced Settings link

6.  In Document Template section, select the Upload a new document template radio button. Click on Browse button to browse and select Loan Request Template.docx document created in step 1. Then click OK button on the screen.

Figure 4 : Upload a new document template

7.  Now to create a new Loan Requests document library, go to Site Actions=>More Options.

Figure 5 : Create document library


8.  Select the Type as Document Library and enter the Loan Requests in the text box. Then click Create button. This will create a Loan Requests document library and will redirect you to AllItems.aspx page (All Documents view).

Figure 6 : Create Loan Requests document library

9.  Click on Library Settings ribbon button. It will redirect you to List Information page.

Figure 7 : Library Settings button

10. Click on Advanced Settings link present under General Settings section.

Figure 8 : List Information page

11. On the Advanced Settings page,  allow content type management on Loan Requests document library using the settings shown in below figure. Then click OK button to save the settings and to navigate to List Information page.

Figure 9: All content type management

12. In the Content Type section on the List Information page, click Add from existing site content types link.
Figure 10 : Add from existing site content type link

13. Now on Add Content Types page, add the Loan Request content type to document library as shown in figure 11. Click OK button.


Figure 11 : Add Loan Request content type

14. In the Content Type section on the List Information page, click on Document content type link to open List Content Type Information page for Document content type.
15. Click on Delete this content type link. Click OK button on delete confirmation popup to delete the Document content type from Loan Requests library.

Figure 12 : Delete Document content type

16. Click on Loan Requests link on Quick Launch menu to navigate to AllItems.aspx page of Loan Requests document library.
17. Click on Documents ribbon group tab.
18. Click on New Document and you will see Loan Request Document template. Click on the same. It will open a document template uploaded in step 6. Note: it also asks for authentication where you will need to give authentication details of currently logged in user.

Figure 13 :  Loan Request Document template

19. Click on Insert ribbon tab in the document. It will display Quick Parts button.

Figure 14 : Quick Parts in the document

20. Now remove the Education Loan from the subject line. Click on Quick Parts button to insert the Loan Type document property as shown in figure below as the place of removed Education Loan text.

Figure 15 : Insert the Loan Type document property into the template

21. Similarly, insert the Loan Reason and Loan Amount document properties into the document so that it looks like as shown in figure below.

Figure 16 : Loan Amount, Loan Type and Loan Reason document properties

22. Save the document to the physical file location as New Loan Request Template.docx.
23. Repeat the steps 5-6 to upload the newly created New Loan Request Template.docx document template.
24. Now using the steps 16-18, create a new document using Loan Request content type. The document properties like Loan Type, Loan Reason and loan Amount can set from the document itself as shown in figure 17

Figure 17 : Enter the Document Property values

25. After entering all the document property values, save the document on the some physical file location as Parwej’s Educational Loan Request.docx.
26. Now navigate to the Loan Requests library and upload the Parwej’s Educational Loan Request.docx document as shown in figure 18.

Figure 18 : Upload the document

27. After clicking OK button, it will show the screen to set the document metadata properties. If you notice, all the values which we added previously as document properties are automatically populated as shown in figure 19.

Figure 19 : Edit form of document

Till now we created site columns, content types, document template for the content type and document library all through browser SharePoint interface.

Now we will see how to create a Library template using Loan Requests library and Visual Studio 2010.

28. Go to the Site Actions=>Site Settings to open Site Settings page.
29. Click on Save site as template link present under Site Actions section.

Figure 20 : Save as site template link
Note: Save site as template link will not be seen when SharePoint Server Publishing feature is activated in site. You can deactivate it for some time to save the site as site template and then reactivate it again.

30. On Save as Template page, click OK button after doing changes shown in figure 21.

Figure 21: Save as Site Template screen

31. Once the site is saved successfully as Site Template, it will display following screen in figure 22. Click on Solution Gallery in the screen.

Figure 22 : Site saved successfully as Site Template

32. Click on Temp link displayed in Solution Gallery. It will ask to save the Temp file. Save it on some physical location.
33. In Visual Studio 2010, create a SPCustomDevelopment project using Empty SharePoint Project template.
Add another project to the solution as shown in figure below.

Figure 23 : Add new project

34. Select the Import SharePoint Solution Package project template as shown in figure below and click OK button.

Figure 24 : Import SharePoint Solution Package project


35. Give any working SharePoint site url and select Sandboxed trust level in the SharePoint Customization Wizard screen as shown in figure 25 and click Next button.

Figure 25 : SharePoint Configuration Wizard

36. On next SharePoint Customization Wizard screen, browse the path of Temp.wsp package saved in step and click Next button.

Figure 26: Specify the new project source

37. On next screen, click on one of the items first. Then use Right Cntrl + A keys to select all items in one go. Then click on them to un-check all of them.
38. Select all the artifacts created through browser interface like Loan Request content type and the site columns, Loan Request list instance. In addition, also select _ctsLoan Request_ module.

Figure 27: Select items to import

39. The project will look like this.

Figure 28 : Imported Project

40. Now delete the 3LoanrequestTemplate.docx from the Modules as shown in figure 29.

Figure 29 :  Delete unnecessary document template

41. Copy paste the Fields, Modules and Content Types folder from WspImportProject1 to SPCustomDevelopment project.
42. Now Add a List Definition From Content Type project item to the SPCustomDevelopment project.

Figure 30 : Add List Definition From Content Type project item

43. Make the following changes Choose List definition Settings screen.

Figure 31 : Choose List Definition Settings

44. Open the Schema.xml file of Loan Requests Template. Change the _CTS to Forms in Folder and Document Template tags as shown in below figure. This will prevent the error which says that only Forms folder have ability to store document templates.

In addition, in List tag add EnableContentTypes="TRUE" attribute.

Figure 32 : Schema.xml changes

45. Add Site Columns, Content Type and List Template features and associated them with the element manifest so that package designer will look like this.

Figure 33 : Package Designer

46. Navigate to site and delete all the site columns, content type and list instance created through browser.
47. Deploy the SPCustomDevelopment project as shown in below figure.

Figure 34 : Deploy Project

This will create new custom “Loan Request Template”.

48. Navigate to site and create a new document library by selecting the Loan Request Template as shown in figure below.

Figure 35 : Create Loan Request list instance

49. It will have the Loan Request document template by default associated as shown in figure below which will open our created custom document template.

Figure 36: Create document using custom document template



I hope using above mentioned approach, you will be able to create complex list/ library templates very easily. Above example also covers how to create custom document templates.

The post was a long one. Time for a much needed break! 

Wednesday, 25 April 2012

SharePoint: Create List Template/ List definition - Part 1

List Template blog series:
Part 1 : Create List Templates/ List Definitions – Traditional approach (Currently reading)

Glad to pull this up after so much difficulties...url blocked in office, no internet/development environment at home and work sufficient enough to keep me busy in weekends also.

Coming to the actual topic, List template is definition or schema of the list where fields, content types, views and forms can be specified. It is used to create multiple lists of same type or structure. We will see how easy it is to create the list definitions step by step.

Create Custom list definition (Traditional Approach):
1.       In Visual Studio 2010, open/create the SPCustomDevelopment SharePoint 2010 project.
2.       In Solution Explorer, right-click the Features node and then click Add Feature as shown in Figure 1.

Figure 1: Add Content Type Feature

3.       Name the feature as SPCustomDevelopment – List Templates and give appropriate description as shown in Figure 2.

Figure 2: Name the Feature

4.       Rename the Feature 1 folder to List Templates as shown in Figure 3 for better readability.

Figure 3: Rename the Feature folder

5.       In Solution Explorer, right-click the SPCustomDevelopment project, select Add, and then select New Item as shown in Figure 4. Type the name as Book List Template

Figure 4: Add List Definition project item

6.       In the next window, make the changes as shown in figure 5 and click Finish button.

Figure 5: List Template wizard

This will create two files, elements.xml and schema.xml. In addition VS 2010 will also associate the newly added Book List Template item to List Templates feature as element manifest.

The elements.xml  contains list template defined using ListTemplate tag. The content types, site columns, list forms and list views to be associated with list template is defined in scehma.xml as shown in figure.

Figure 6: List Schema structure

7.       In schema.xml remove the Item and Folder content type references and add Book content type in the ContentTypes tag as shown in Figure 7. Note that multiple content types can be associated with single content type. (copy the content type definition from schema given in step no 9)

Figure 7: Copy content types into the schema

Note that instead of mentioning all the content type definition, only reference to content types also can be mentioned in the schema.xml using ContentTypeRef tag.

8.       Add site columns definitions into the Fields tag as shown in Figure 8.  (copy the field definitions from schema given in step no 9)

Figure 8: Add site columns into the schema

9.       Name the view having BaseViewID equal to 1 as All Books and change its ViewFields as shown in figure 9.

Figure 9: Create a List View

Note that the other view operations like grouping, filtering the items can also be defined in the view definition of schema in Query tag.

Figure 10: View Operations

Now your schema will look like this.

<?xml version="1.0" encoding="utf-8"?>
<List xmlns:ows="Microsoft SharePoint" Title="Book List Template" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/BookListTemplate" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">
  <MetaData>
    <ContentTypes>
      <ContentType ID="0x0100921DB927A11B42709A0C51C4A37EA816"
               Name="Book"
               Group="SharePoint 2010 Custom Development"
               Overwrite="TRUE"
               Version="0"
               >
        <FieldRefs>
          <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" Required="TRUE" DisplayName="Book Name"/>
          <FieldRef ID="{6F87C38C-5218-45D8-905E-877D694ECC31}" Name="Technology"/>
          <FieldRef ID="{52AE411D-32FB-484C-A04F-ED6C7E41A593}" Name="Publication"/>
          <FieldRef ID="{7D8A68DA-3A2D-444D-A721-1E7A6633402B}" Name="PriceOfBook"/>
          <FieldRef ID="{E93762F1-6F7E-4DFC-9161-0B3B35A7BE35}" Name="BookAuthors"/>
        </FieldRefs>
      </ContentType>
    </ContentTypes>
    <Fields>
      <Field ID="{6F87C38C-5218-45D8-905E-877D694ECC31}"
         Type="Choice"
         Name="Technology"
         StaticName="Technology"
         Description="Select the technology on which this book is written."
         DisplayName="Technology"
         Format="Dropdown"
         Group="SharePoint 2010 Custom Development"
         Required="TRUE"
         Overwrite="TRUE"
         >
        <CHOICES>
          <CHOICE>C#</CHOICE>
          <CHOICE>ASP.NET</CHOICE>
          <CHOICE>SharePoint 2010</CHOICE>
          <CHOICE>MOSS 2007 and WSS 3.0</CHOICE>
        </CHOICES>
      </Field>
      <Field ID="{52AE411D-32FB-484C-A04F-ED6C7E41A593}"
             Type="Text"
             Name="Publication"
             StaticName="Publication"
             DisplayName="Publication"
             Description="Type the Publication of this book."
             Group="SharePoint 2010 Custom Development"
             Required="TRUE"
             Overwrite="TRUE"/>
      <Field ID="{7D8A68DA-3A2D-444D-A721-1E7A6633402B}"
             Type="Currency"
             Name="PriceOfBook"
             StaticName="PriceOfBook"
             DisplayName="Price"
             Description="Enter the book cost."
             Group="SharePoint 2010 Custom Development"
             Required="TRUE"
             Overwrite="TRUE"/>
      <Field ID="{E93762F1-6F7E-4DFC-9161-0B3B35A7BE35}"
             Type="UserMulti"
             Name="BookAuthors"
             StaticName="BookAuthors"
             DisplayName="Authors"
             Description="Enter the book authors"
             Group="SharePoint 2010 Custom Development"
             Required="TRUE"
             Mult="TRUE"
             UserSelectionMode="0"
             UserSelectionScope="0"
             Overwrite="TRUE"/>
    </Fields>
    <Views>
      <View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE">
        <Toolbar Type="Standard" />
        <XslLink Default="TRUE">main.xsl</XslLink>
        <RowLimit Paged="TRUE">30</RowLimit>
        <ViewFields>
          <FieldRef Name="LinkTitleNoMenu"></FieldRef>
        </ViewFields>
        <Query>
          <OrderBy>
            <FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
          </OrderBy>
        </Query>
        <ParameterBindings>
          <ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" />
          <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
          <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_ONET_HOME)" />
        </ParameterBindings>
      </View>
      <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="All Books" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx">
        <Toolbar Type="Standard" />
        <XslLink Default="TRUE">main.xsl</XslLink>
        <RowLimit Paged="TRUE">30</RowLimit>
        <ViewFields>
          <FieldRef Name="LinkTitle"></FieldRef>
          <FieldRef Name="Technology"></FieldRef>
          <FieldRef Name="Publication"></FieldRef>
          <FieldRef Name="PriceOfBook"></FieldRef>
          <FieldRef Name="BookAuthors"></FieldRef>
        </ViewFields>
        <Query>
          <OrderBy>
            <FieldRef Name="ID"></FieldRef>
          </OrderBy>
        </Query>
        <ParameterBindings>
          <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
          <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
        </ParameterBindings>
      </View>
    </Views>
    <Forms>
      <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
      <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
      <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
    </Forms>
  </MetaData>
</List>



10.   Deploy the project by pressing F5.
11.   Once deployment is successful, Book List Template will be created as shown in figure 11. It can be used to create multiple lists of type Book List Template having same structure.

Figure 11: Newly Added Book List Template


One important thing to remember here is, fields and content types in schema.xml are list fields and list content types.You can create list fields and list content types without creating site fields and site content types.


Custom list forms

There are various ways to modify the list forms. Few are mentioned in my last blog Basicsof Content Types where forms are associated with content types instead of list directly. List schema (schema.xml) too provide a way to associate custom list forms through Forms tag which once associated, are used for all list content types.

I am not going into details how to associate the custom list forms to list using Forms tag. It is best explained by Igno Karstein his two blogs with examples.

Even though I personally like creating list definitions using above traditional approach as I believe it helps me to understand/learn the list definitions, fields and content types all together in better way. There is another approach to create list definition using which you can generate the list definition schema. It does not require knowledge of field, content type schemas. Will cover that in my next blog in this series.