LINQ query on a DataTable

You can’t query against the DataTable‘s Rows collection, since DataRowCollection doesn’t implement IEnumerable<T>. You need to use the AsEnumerable() extension for DataTable. Like so: var results = from myRow in myDataTable.AsEnumerable() where myRow.Field<int>(“RowNo”) == 1 select myRow; And as @Keith says, you’ll need to add a reference to System.Data.DataSetExtensions AsEnumerable() returns IEnumerable<DataRow>. If you need … Read more

Creating a byte array from a stream

It really depends on whether or not you can trust s.Length. For many streams, you just don’t know how much data there will be. In such cases – and before .NET 4 – I’d use code like this: public static byte[] ReadFully(Stream input) { byte[] buffer = new byte[16*1024]; using (MemoryStream ms = new MemoryStream()) … Read more

LINQ’s Distinct() on a particular property

What if I want to obtain a distinct list based on one or more properties? Simple! You want to group them and pick a winner out of the group. List<Person> distinctPeople = allPeople .GroupBy(p => p.PersonId) .Select(g => g.First()) .ToList(); If you want to define groups on multiple properties, here’s how: List<Person> distinctPeople = allPeople … Read more

Script References not loaded in Partial PostBack when specified as "new ScriptReference(resourceName,assemblyName)"

This appears to be an issue with SharePoint 2010 and I was finally able to dig up some information on this post. This is a known issue in Sharepoint 2010. The script resources are not loaded if the controls are not visible initially .. .. The “Sharepoint 2010 not emitting javascript links on partial postback” … Read more