February 6, 2009 08:30 by
bryan
Okay you are developing a WinForm application and you are looking at performance, one area is Caching of information, but wait a minute I've been using caching in my web applications for sometime, but how do you do it from a WinForm application as you don't have a host to store your cache.
Would you know it you can use the web cache too, just you have to take a few extra steps to retain your cache, either in memory or in temporary files.
You can use the HttpRequest to store the System.Web.Cache objects in your application, and this works well.
I also came across any Blog, providing another method to Caching, however I have a little concern over this method of caching in files as you are likely to get file locking.
Using System.Web.Caching From The Console Or Windows Forms
I've written my own simple VB.NET application to show it working and just holding the Cache in memory for the life of the application.
WinFormCache.zip (17.73 kb)
Of course you could run a Windows Service which holds all the Cache information, this way it will be available to all your WinForm applications should you require it.
8c3849f3-9342-4d00-a7af-8f51e8b23a2e|2|3.0
December 22, 2008 10:17 by
bryan
The latest fad is to create Carousels to display images, and allow for easy navigation. I have not been able to find any .NET controls to enable you to create a Carousel on a web page.
So I set myself the task of generating a web page control to allow for easy, managed code, configuration of a Carousel Control in .NET
First I went on the hunt for a simple javaScript Carousel that I could use, I found a lovely Carousel by Doug Greenall, the information on his blog goes in to great detail of how the Carousel works, but this was not intention to go in to detail about the inner working of a Carousel.
So I downloaded Doug Greenall's Carousel and then went to adapt the javaScript code to create a single DLL Control that could be reused.
The end product is a small DLL that can be dragged and dropped in to your ASP.NET application or Website
Carousel.dll (21.50 kb)
The project solution was generated using Visual Studio 2008 Pro,with a Target Framework of ".NET Framework 2.0"
Carousel.zip (191.73 kb)
How to use the Carousel
Okay, so now I've built the Carousel Control, you now want to to know how to use it?
-
First create a new WebSite
-
Add the Carousel.dll or a project reference to your website
-
On the web page register the control (or add it to your web.config)

- Next in the code behind you need to add to the CarouselDetail collection, which will add the images, links to the Carousel
And that is it, the more you add to the CarouselDetail collection the more items will appear on the Carousel.
daa40290-e5c2-4a1e-bc20-ad877d92ca4d|3|3.3
December 22, 2008 10:01 by
bryan
I've always been able to create a standalone DLL control that can be reused in other web applications. I've never really found out how to embed other resources, or more to the point JavaScript files.
Until now
Here's how to embed the file:
- Create a js file such as carousel.js
- In Visual Studio, select the file in Solution Explorer and change the Build Action property to "Embedded Resource"
- Build the project and the carousel.js file is now part of the assembly (you don't need to distibute the js file now it's part of the assembly)
Now to get the resource out using code:
So if we have a resource named Control.carousel.js we can use the following to include it in our page:
System.IO.Stream script = Assembly.GetExecutingAssembly().GetManifestResourceStream("Control.carousel.js");
System.IO.StreamReader sr = new System.IO.StreamReader(script);
Page.ClientScript.RegisterClientScriptBlock(GetType(), "carousel", sr.ReadToEnd().ToString(), true);
sr.Close();
The above code injects the embedded file in to the page, how easy could it be?
d97f4ee7-7425-4fd3-b620-689d631e77c7|2|3.0
December 15, 2008 13:29 by
bryan
Oh how I remember those days of page through data, using a GridView controller, or any other controller, lots of coding and so easy to make a mistake.
Just take a look at http://www.unboxedsolutions.com/sean/archive/2005/12/28/818.aspx by Sean Chase, and you will see what I mean.
Things have moved on a bit since those days, and now we have LINQ it is much easier, both directly feeding from LINQ or via methods, both provide the same result.
Linq DataSource
Here is how to enable paging directly to LINQ, by using the LinqDataSource

How easy could it be?
Linq Methods
When it comes to generating your own method you can do this with just a little more coding and take advantange of the Linq Skip and Take methods, the sample below provides an example using a Method.

To use this fully you will need to make a few changes to the webpage, as shown below:

Now that you have everything set on the page all that is left is the code behind and the methods, I am using the partial class in the example, but it does not have to be.
Code Behind

Methods
To ensure that the application is Paging correctly I found running the SQL Profiler on the database made sure that only the data page was being returned and nothing else, you may want to perform your own tests too.
I have included a small application using Visual Studio 2008 and .NET 3.5, all you will need to change is the connection string settings to the NorthWind database.
GridPerformance.zip (16.46 kb)
73df9791-1f7c-48f9-843f-0d4bc0a24089|1|1.0
November 24, 2008 13:08 by
bryan
2d200e6e-4477-4aae-8291-4b6584966460|1|1.0
November 18, 2008 15:58 by
bryan
6b49f4ba-b51a-4b13-b793-103ba9f50ce7|1|1.0
November 18, 2008 12:33 by
bryan
QUESTION: What is the easiest way to find the difference between two dates?
DateTime userLoginTime = (DateTime)roteTimeout.LastLoginTime;
TimeSpan span = DateTime.Now.Subtract(userLoginTime);
if (span.Seconds > userTimeout.TimeoutPeriod)
{
}
ecec5e20-9c4f-4391-894a-46771e5acc8d|1|1.0
November 15, 2008 07:20 by
bryan
e06af041-d673-4da9-b6f6-838f715b14a6|1|1.0
November 10, 2008 09:13 by
bryan
Need to change the membership provider programmatically?
string username = "user";
string password = "password";
MembershipUser membershipUser = Membership.Providers["SqlMembershipProviderOther"].GetUser(username);
membershipUser.ChangePassword(membershipUser.ResetPassword(), password);
Also worth checking out here
2058d1f1-0cdf-444d-b67e-f6862b0a8882|1|1.0
November 5, 2008 12:05 by
bryan
If you are building an application for general release, and would like to build it using .Net 3.5 SP1, it would be nice to know if the end users already have .Net 3.5 SP1.
We can safely say that the majority of end users has .Net 2.0, as this is part of the Windows update process.
Currently to upgrade to .Net 3.5 SP1 you will need a separate download,which is not a small download.
Help is at hand as Microsoft will be shipping the .Net 3.5 SP1 through Windows Update, for all users that have .Net2.0 installed, and Windows update enabled, this will be available in January 2009.
This does not apply to Visual Studio 2008, as you will still require a separate download.
[more]
718f626e-da43-4536-9681-d6eb862649ab|2|3.0