Caching from a non Web applications

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.


How to create a Carousel in a webpage

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)

  • Then add the control to the page, as seen below

 

  • 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.


Embedding javascript in an assembly

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:

  1. Create a js file such as carousel.js
  2. In Visual Studio, select the file in Solution Explorer and change the Build Action property to "Embedded Resource"
  3. 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?

 


LINQ to SQL and Paging

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)


Membership and Security

November 24, 2008 13:08 by bryan

Always good to go back to basics, where ever I go I have the need to generate a security environment which is based on the MembershipProvider.

There are lots of examples out on the Internet so it makes it hard to find what you are after, everytime I end up back at the same website, as it take you through the basic Membership and then goes in to it in depth, such as switching users if you are an administrator.

Examining ASP.NET 2.0's Membership, Roles, and Profile

Manage Custom Security Credentials the Smart (Client) Way

Not every application is a Web Based application, people still create WinForm application, so if you are using a WinForm application it's worth looking at this article

Using the ASP.NET membership provider in a Windows forms application


Team Foundation Server Addon's

November 18, 2008 15:58 by bryan

There is an increasing number of Team Foundation Server Addon's, here are a list that might be of use 

Working remotely and need to collaborate, check this out Working Skype Collaboration Provider for TFS

 


Difference between two dates

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) 

{


Writing to the Event Log from your Application

November 15, 2008 07:20 by bryan

Have you tried to write to the Event Log from within your application?

It's not hard to write to the Event Log these days, in fact .Net makes it quite easy.

Where the issue come is when you deploy your application you find the the operating environment does not have enough permissions.  I found a good article this morning on how to over come this by Rory Primrose

http://www.neovolve.com/post/2008/11/12/Creating-event-log-sources-without-administrative-rights.aspx 

 


Changing Membership provider

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 

When will .Net 3.5 sp1 be available on all machines?

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