Sunday, May 16, 2010

Simple Linq Sample in Word Vsto

Using Linq In Word Vsto The Below Sample Shows very Basic use of Linq with VSTO word.

Requirement:-

Vs 2008
Vsto

Code:-

private void ThisDocument_Startup(object sender, System.EventArgs e)
{
Linquse_InWord_Vsto("Avinash Tiwari Linq Sample");
}

public void Linquse_InWord_Vsto(String strText)
{

var qChars = from c in strText select c;
int charCount = qChars.Count();

List textWords = new List(strText.Split(new char[] { ' ' }));
var qLetterWords = textWords.FindAll(x => (x.Length >= 2));

this.Application.Selection.InsertAfter("\n Character Count: " + charCount + "\n Word Count: " + qLetterWords.Count);

this.Application.ActiveDocument.Content.InsertBefore(strText);


}

Output:-



No comments:

Post a Comment