Microsoft Office Tutorials and References
In Depth Information
What is LINQ?
What is LINQ?
LINQ is a programming model that introduces queries as a first-class concept
into any Microsoft .NET language. LINQ is all about queries, whether they are
queries returning a set of matching objects, a single object, or a subset of fields from
an object or a set of objects. LINQ is one of the key features of the Microsoft .NET
Framework 3.5.
LINQ queries can directly populate an object hierarchy, and parameterization
is automatic and type-safe, which is more extensive in application development.
In Visual Studio 2008, nearly all projects automatically include references to
System.Core and System.Xml.Linq , where most of the LINQ classes are defined.
Using LINQ in Word 2007 with VSTO 3.0 and Visual
Studio 2008
1. Open Visual Studio 2008, to create a new Word 2007 Document
template project.
2. Select New Project . Under Office , select 2007 and then select the Word 2007
Document template, and name the project as you wish.
3. Next, you need to select the document type, and name the document for
your solution.
4. The solution will be created with all of the supporting files required for the
development of our Word solution.
5. In the Startup event of the Word document, let's do some string
manipulation using LINQ.
6. In this simple demonstration, you are going to see how to query a string and
retrieve the number of words in the string. This is going to be achieved by
using LINQ and lambda expressions. A lambda expression is an unspecified
function that can contain expressions and statements, and all lambda
expressions use the lambda operator ( => ), which is read as "goes to".
private void ThisDocument_Startup(object sender, System.EventArgs
// String to store the title text
String strText = "Beginning VSTO from PacktPub";
// Use LINQ and implicit types to get the word count
var qChars = from c in strText select c;
int charCount = qChars.Count();
// Use lambda expression to get the number of words.
List<string> textWords = new List<string>(strText.
Split(new char[] { ' ' }));
Search JabSto ::

Custom Search