Thursday, July 23, 2009

Code Snippet: List<T>.Sort()

Sorting a generic list of objects using a delegate

List<Filter> filters = new List<Filter>();

filters.Add(new Filter("Z", "Zebra", (int)FilterCategoryEnum.RaamsProdOption));
filters.Add(new Filter("M", "Mars", (int)FilterCategoryEnum.RaamsProdOption));
filters.Add(new Filter("B", "Bellow", (int)FilterCategoryEnum.RaamsProdOption));
filters.Add(new Filter("K", "Karate", (int)FilterCategoryEnum.RaamsProdOption));
filters.Add(new Filter("A", "Arawak", (int)FilterCategoryEnum.RaamsProdOption));

filters.Sort(delegate(Filter a, Filter b)
{ return Comparer<string>.Default.Compare(a.FilterValue, b.FilterValue); });

Thursday, July 16, 2009

Code Snippet: List<T>.FindAll()

Find all products in the specified category

private List<product> FindProductssByCategory(List<product> products, ProductCategoryEnum category)
{
return products.FindAll(delegate(Product p) { return p.CategoryId == (int)category; } );
}

Code Snippet: List<T>.Exist()

Find the given product in the list of saved product

List<Product> savedProducts = Repository.GetSavedProducts();
Product item = (Product)dataItem.DataItem;
bool found = savedProducts.Exists(delegate(Product p) { return a.ProductName == item.ProductName; });

Sunday, March 8, 2009

Recreating a missing ASPNET machine account

ASP.NET 2.0 uses NETWORK SERVICE or the ASPNET machine account as it's service account. NETWORK SERVICE is using on Windows 2003 Server and ASPNET is normally used on Windows XP Professional. If you find yourself needing to recreate the ASPNET machine account to allow ASP.NET applications to work properly you can do so using the following method:

1. Create the account using the same name (ASPNET) or any name you choose
2. Go to a command prompt and run the following command:

%systemroot%\Microsoft.NET\Framework\[current version]\aspnet_regiis.exe -ga [ACCOUNTNAME]

The last step will apply the appropriate permissions to allow the new account to access the IIS metabase.

About Me

Software developer specializing in Microsoft technologies.