Thursday, October 16, 2008

List.Exists(Predicate match)

Hi,

At times when you want to check for an Item inside a List list, you can use the Exists method as follows.

List.Exists(Predicate match)

List l = new List();
l.Add("Red");
l.Add("Green");
l.Add("Blue");
l.Add("Purple");

//prints "true" as "Red" is in the list
Console.WriteLine(l.Exists(delegate(string s) { return s == "Red"; }));

//prnts "false" as "Pink" is not in the list
Console.WriteLine(l.Exists(delegate(string s) { return s == "Pink"; }));
Published 30 September 04 08:00 by BradA
http://blogs.msdn.com/brada/archive/2004/09/30/236460.aspx

In my case I had to check against an object and not the string.

this will work, SourceFieldID is of type string.
bool itemExists = _criteriaItems.Items.Exists(delegate(CriteriaItem ci) { return ci.SourceFieldId == item.SourceFieldId; });

but this wont work, it will always return false.
bool itemExists = _criteriaItems.Items.Exists(delegate(CriteriaItem ci) { return ci == item; });

happy coding!!

Wednesday, September 10, 2008

Patterns and Practices Guideline Explorer

Patterns and Practices Explorer
A very useful tool and knowledge base for the believers of Patterns and Practices.


Link to Home Page
Link to Download

It gives you some very nice guidelines to go through in a given technology for example, Please look at the attached pic.

click the Image to see it better.



enjoy!!

Wednesday, September 26, 2007

using Indexing Server from .NET

I had to write the Indexing Server code to search within the file in VB6 and I again had to write it but this time in .net. Following is the Simplest way we can get the same thing done in .NET.
You have to have your Catalog created in your Indexing Server in Component Management Console (Start->run->Compmgmt.msc)

string strCat = "DWF"; //Your Catalog in Index Server
string strQuery = "Select DocTitle,Filename,Size,PATH,URL from SCOPE() where FREETEXT('" + Convert.ToChar(34) + text + Convert.ToChar(34) + "')";
//CONTAINS(Contents, '" + TextBox1 + "')";
//FREETEXT('" + TextBox1.Text + "')";
string conStr = "Provider=MSIDXS.1;Integrated Security .='';Data Source='" + strCat + "'";
cn.ConnectionString = conStr;
cn.Open();
OleDbDataAdapter DA = new OleDbDataAdapter(strQuery, cn);
DataSet testDataSet = new DataSet();
DA.Fill(testDataSet);
//Bind DataGrid to the DataSet. DataGrid is the ID for the
//DataGrid control in the HTML section.

DataView source = new DataView(testDataSet.Tables[0]);
GridView1.DataSource = source;
GridView1.DataBind();

Enjoy!!

Useful .net Code Examples

101 Useful .net Code Examples
I found them Useful!!
http://msdn2.microsoft.com/en-us/vstudio/aa718334.aspx
some of them needs AdventureWorks Database installed and configured on your machine with SQL Server 2005 Express
http://www.codeplex.com/MSFTDBProdSamples/Release/ProjectReleases.aspx?ReleaseId=5705
if you can’t install the Database with the AdventureWorksDB.Msi on above page,
try AdventureWorksDBScript.msi. It’s the Database Script and you need to run it to create the Database.
Make sure @data_path is set perfectly. It should be the path of the directory where you have install the script files in the MSI installer.
I had to change it as follows
SET @data_path = 'C:\Program Files\Microsoft SQL Server\100\tools\Samples\AdventureWorks OLTP\';
Or it wasn’t doing the BULK Inserts because it wasn’t finding the path of .CSV files that also gets installed by the MSI.
Happy Learning!!

Multithreading Article

This link consists some very good articles on Multithreading!!
the Article
Enjoy !