Friday, September 24, 2010

Sharepoint 2010 - New List Features

In this post, I will describe some of the new things introduced with lists in SharePoint 2010.
Some of these things are
1. Referential Integrity:-
As you know, with SharePoint 2007 we can create relationship between lists using Lookup field. But now, List in SharePoint 2010 also supportsReferential Integrity with another list. So if you have two lists Student and Department, you can create a referential integrity constraint (Cascade Delete or Restrict Delete) between them.
  1. Cascade Delete: Means if item in the parent list is deleted all the associated items in the child list will also be deleted (just like in SQL Server)
  2. Restrict Delete: If an item in parent list is associated to items in the child list, then this item in parent list cannot be deleted unless its association with all the items from the child list is removed.
Here in below example, I have created two List “Student” & “Department”. And now I am creating a relationship between “Student” and “Department”. For this I have to create a column in “Student” list. See the diagram below. (Also see the referential integrity constraint between the two list set to “Restrict Delete”, which means the “Department” cannot be deleted if there are one or more “Student” related to it, just like between any two SQL tables).
image

2. Projected Fields in Lists:-
These are fields from the parent list which will appear in the view of the child list. These are additional fields from the parent list to be shown in the child list. E.g. from the above diagram, Department Location from the department will be shown in the student list. These fields are NOTsaved in the child list (Student) and will be only shown in the child list. See the diagram below. Here the “Department Location” is a “Project Field” from the “Department” list to be shown in the “Student” list, but it is not saved in the “Student” list.
image
image
3. Unique Columns:-
You can create unique column (meaning the column will hold the unique data) inside a list in SharePoint 2010. The unique column MUST be indexed. So while creating the unique column, SharePoint 2010 will ask you to index the Unique Column. E.g. Student “Registration No” can be a unique column in the “Student” list. You can also make any existing column as unique column provided it has unique data for all the list items.
4. JOIN and Querying Data from Two Lists:-
Developers can query the SharePoint 2010 List using CAML and LINQ to SharePoint and select fields from two different lists as shown in the code below. Here in the below code ( LINQ To SharePoint), I have retrieved all the “Students” for the Department “Computer Science”.
Note: - In order to use LINQ to SharePoint you have to generate the “SharePoint Context” from the SPMetal tool (now comes as a part of SharePoint 2010), which is located at the following directory. (“C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN”). Here is syntax to generate your Context.cs file.
SPMetal /web:http://mossserver:8000 /namespace:SPTeamSite /code:SPTeamSite.cs
After this create a new project in VS2010, add the reference to Microsoft.SharePoint.Linq.dll & Microsoft.SharePoint.dll located at the following directory. (“C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI”). Also add the SPTeamSite.cs file generated from the SPMetal tool. See the diagram below.
image
Now here is the code to retrieve all the “Students” of a particular “Department”.
image
image
Lists in SharePoint 2010 have a lot more to offer. I will do more posting on the new features of Lists in SharePoint 2010 as I learn more about it.
Cheers :)

Thursday, September 23, 2010

Working with Silverlight

Here are some examples of integrating silverlight and javascript





Add this reference to your code behind

using System.Windows.Browser;

Simple call :

private void btnFonctionJs_Click(object sender, RoutedEventArgs e)

{

HtmlPage.Window.Invoke("AfficheMessage");

}
Call with parameters

private void btnFonctionJsParam_Click(object sender, RoutedEventArgs e)

{

HtmlPage.Window.Invoke("AfficheMessageParam", new string[] { "Salut!" });;

}

call with anonymous javascript function

private void btnJsInline_Click(object sender, RoutedEventArgs e)

{

HtmlPage.Window.Eval("(function(){ alert('Fonction anonyme Js inline depuis Silverlight 2'); })()");

Working with Sharepoint Properties on 2010

SharePoint WebPart Property Attributes



I wanted to put this information out there because it was not well published when I was building WebParts for the first time. When you build a WebPart in MOSS 2007 you have the ability to expose the public properties of the WebPart in the editor pane of the WebPart page. This allows you to set some administrative values for the WebPart behind the scenes. In order to make this happen you have to tag the property as being Web Browsable.




Unfortunately most of the documentation only gives information on the WebBrowsable and Personalizable attributes. However there are a few others that you might find valuable to know about. Some of the other attributes are listed below along with explanations and links to further resources.


WebBrowsable [WebBrowsable(True)]


"Indicates whether the designated property of a Web Parts control is displayed in a PropertyGridEditorPart object." (MSDN)



WebPartStorage [WebPartStorage(Storage.Personal)]


This attribute specifies what type of storage options the WebPart will make use of. The most common is Storage.Personal. "This property can be personalized by individual users. Its WebPartStorageAttribute value is Storage.Personal, which specifies that the property can be stored on a per-user basis. Only users with the Personalize Web Part pages right can set this property." (MSDN)

Personalizable [Personalizable(true)]


Allows users the ability to personalize settings for the WebPart.



WebDispayName [WebDisplayName(string)]


Defines the Friendly Name for a property of a WebPart control. This is the name that will show up in the editor screen.


WebDescription [WebDescription(string)]


Defines the string value to use as a ToolTip for a property of a Web Parts control. (MSDN)



SPWebCategoryName [SPWebCategoryName(string)]


Defines the friendly or localized name of the category of a property in the CustomPropertyToolPartcontrol inside the ToolPane.



ConnectionProvider [ConnectionProvider(string)]


Identifies the callback method in a server control acting as the provider in a Web Parts connection, and enables developers to specify details about the provider's connection point. (MSDN) This is used to create connectable WebParts.



ConnectionConsumer [ConnectionConsumer(string)]


Identifies the callback method in a server control acting as the consumer in a Web Parts connection, and enables developers to specify details about the consumer's connection point. (MSDN) This is used to create connectable WebParts.



Below is an example of how to use these attributes in your WebPart code.



[WebBrowsable(true),


Personalizable(false),


WebPartStorage(Storage.Personal),


WebDisplayName("User Name(Domain\\username)"),


WebDescription("User to display in the WebPart."),


SPWebCategoryName("Options")]


public string UserLoginName


{


get { return _loginName; }


set { _loginName = value; }


}



Happy coding!

Saturday, September 11, 2010

Silverlight Development

In my new role one of my new responsabilties is the development of Silverlight applications, and then include them inside my sharepoint projects, so here we go with some tips.

To display Alert Box, use:
System.Windows.Browser.HtmlPage.Window.Alert("Alert Message");
To display Input box (prompt), use:
string strValue = System.Windows.Browser.HtmlPage.Window.Prompt("What is your age?");
To display confirm box, use:
bool blnResult = System.Windows.Browser.HtmlPage.Window.Confirm("Are you sure?");

So since now I am including some silverlight tips and tricks on my posts.

I will be expecting your comments.