July 31, 2010
Developer In-Depth:
prev
next
- Podcast
- Research
- Search
- Security
- Technology
- Video
- AIM
- Alfresco
- Collaboration
- ECM
- ESX
- Hyper-V
- IE8
- Internet Explorer
- Iomega
- Linux
- MIX08
- Microsoft
- NAS
- Nokia
- REV
- S60
- SaaS
- Sharepoint
- Silverlight
- Sony Ericsson
- VMware
- Windows Live
- YouTube
- Advertising
- Backup
- Beta Test
- Blogs
- Convergence
- Display
- Enterprise
- Humans
- Instant Messaging
- Multimedia
- Networking
- Open Source
- Phishing
SharePoint 2010 Makes the Link to LINQ
LINQ (or Language Integrated Query) has been extensively used by the developer community in the last couple of years. Its rich semantics, compile-type checking, along with "intelliSense" support in Visual Studio, offer many advantages for developers. SharePoint developers, however, did not get to enjoy LINQ for the most part, because there was no support for it in SharePoint 2007. (There were some efforts from community members to enable using LINQ with SharePoint 2007 by using custom-made tools.) But wait no more, because LINQ to SharePoint finally arrived in SharePoint 2010. As expected, it provides the running of LINQ queries over the SharePoint 2010 Lists / Libraries. Internally, LINQ to SharePoint generates the laborious CAML queries; this takes the burden of writing complex CAML queries away from the developer, so his or her time can better spend on other productive tasks. However, please note that CAML is still fully supported in SharePoint 2010, and in certain scenarios it may be better fit than LINQ. This article will show you how to use tool a called "SPMETAL" to generate the source code file for LINQ to SharePoint, then use it to query the SharePoint List, and finally insert the item in the List. For an example, a create a SharePoint "Custom List" called "Customers." You can give custom lists any name, just make sure you end up having two custom columns named "Name" and "Address," both of type "single line of text." Also add an item to the list. The following image shows the list item along with columns.
The new utility called "SPMETAL.exe" will be used to generate the source code file that will be used to perform LINQ to SharePoint queries. Perform the following steps to generate the source file.
1. "SPMETAL.exe"
is located in "BIN" inside the SharePoint installation directory.
"<Drive-Letter>:\Program
Files\Common Files\Microsoft Shared\Web Service Extensions\14\BIN". Where
"<Drive-Letter>" is the drive where SharePoint is installed.
2. Execute the "SPMETAL" command, along with parameters as shown below.
4. The source file is ready. In order to utilize it, create a new "Windows Console Application" project in Visual Studio 2010, use "Visual C#" because the source code generated by "SPMETAL" was in C# (in case you want to work with VB.NET just change the ".cs" to ".vb" in step 2, this will result in source file for VB.NET. Technically speaking, Visual Studio 2010 is not mandatory. The only thing required is an application that can leverage the code file to perform LINQ to SharePoint queries. However the requirement that the application must be compiled against "x64" still stands, if the target platform is different, SharePoint will not be accessible. Once the project is created, add the source file to the project. The following image shows the project after the source file "SharePoint.cs" is added.
Networking Solutions
Most Popular Stories
- 1 Building SharePoint Suggestion Boxes and Soliciting Anonymous Feedback
- 2 Moving a Document to the SharePoint 2010 Records Center
- 3 Solve Item-Level Permission Performance Problems in SharePoint
- 4 Developing SharePoint Solutions in Visual Studio Using WSPBuilder
- 5 Using the Event Handler in SharePoint 2010
- 6 Prepare Your SharePoint Data Carefully, Ediscovery Experts Warn
- 7 Design a Form to Collect Customer Information Using InfoPath and SharePoint 2010

Extending database skills is fast and easy with new features and this e-kit. Learn how and start taking advantage of easier DB2 administration features today.