Posted by Paul Welter on Monday, August 13 2007 at 3:24 PM

I wanted to be able to cache the results of a query from the LinqDataSource that was used in multiple places on the page.  I whipped up this little class to do the work of caching for me.  The class, LinqCacheDataSource, handles the Selecting and Selected events.  The Selected handler inserts the result of the query into cache.  The Selecting handler gets the result from the cache.  If it doesn't find the result, the query runs as normal.  The caching will only work for selecting data.  It works great for dropdowns and other fairly static data.

Read More ...

No Comments Posted in: Snippets    Tagged as: ,
Posted by Paul Welter on Thursday, May 31 2007 at 5:48 PM

The following query extension will make paging a query more natural then skip and take. Simply append Paginate(page, pageSize) to your query.

Read More ...

No Comments Posted in: Snippets    Tagged as: ,
Posted by Paul Welter on Wednesday, May 03 2006 at 12:13 PM

For some reason, the generic Dictionary in .net 2.0 is not XML serializable.  The following code snippet is a xml serializable generic dictionary.  The dictionary is serialzable by implementing the IXmlSerializable interface.

Read More ...

No Comments Posted in: Snippets    Tagged as: , ,
Posted by Paul Welter on Wednesday, February 08 2006 at 1:38 AM

Here is a code snippet that is equivalent to the windows API PathRelativePathTo as native c#. The function creates a relative path from one file or folder to another.

Read More ...

No Comments Posted in: Snippets    Tagged as: , ,
Posted by Paul Welter on Saturday, August 13 2005 at 7:54 PM

Here is a little test code that demonstrates how to use Generics at runtime. The code has two tests. The first test shows how to create a Generic Class at runtime. The second shows how to call a Generic method. Keep in mind that when using generics at runtime, there will be a reflection performance hit.

~ Paul

Read More ...

No Comments Posted in: Snippets    Tagged as: ,
Posted by Paul Welter on Friday, July 01 2005 at 12:00 AM

Here is the handy Stopwatch class from .net 2.0 framework back ported .net 1.1. Enjoy…

Read More ...

No Comments Posted in: Snippets    Tagged as: ,
Posted by Paul Welter on Friday, September 03 2004 at 1:18 PM

Here is a useful code snippet to convert the tense of a word from single to plural and vise versa. The code uses a series of regular expression to examine the word and convert it using the correct grammar.

Read More ...

No Comments Posted in: Snippets    Tagged as:
Posted by Paul Welter on Friday, August 06 2004 at 6:20 PM

In my work with the RichTextBox control, I've often run into this bug in the RichEdit control. You can read more about this bug by looking at Microsoft's knowledge base article - 812943. If you are unable to get the latest Riched20.dll then you can get around the problem using the following code …

Read More ...

No Comments Posted in: Snippets    Tagged as: ,