Beware Visual Studio 2008 Beta 2 VPC will expire before time

Hi,

I just saw this news and thought I will help in spreading it around, as I know many people have been using Visual Studio 2008 Beta 2. The VPC of the Beta 2 of Visual Studio 2008 will expire on 1st November 2007 instead of expected in march next year.

The problem is with the timeout at the OS level. You need to backup all file before that otherwise you will loose all the your good work.

Read this post for more information.

http://weblogs.asp.net/bryansampica/archive/2007/10/27/important-information-regarding-visual-studios-2008-beta-2.aspx

Vikram


Working with Asp.Net profile properties to save user specific information

Hi,

Many a times we need to keep unique information of the user in the web application so that the information can be used for the user when required. For example, you can allow the user to choose the background image of the site. Or even let the user select a theme from the many themes in the site.
[Note: The multiple theme property has already been incorporated in my site. You can choose the Change The Theme button in the left top to change the theme of this site.]

We normally want to store some values for individual user, so as to allow personalization of the site for individual user. These profile values need to be stored in database so that they can be retrieved and used when the user visits again.

Continued...

C sharp Difference between the out and ref type parameters

Hi,

In C Sharp(C#) we can have three types of parameters in a function. The parameters can be In parameter (which is not returned back to the caller of the function), Out parameter and ref parameter (where by a reference to the variable is passed back).

The last two type (out and ref) mentioned looks quite similar in nature. Both parameters are used to return back some value to the caller of the function. But still there is a small but important difference between them. Both of the parameter type has been kept in the C# language for specific scenario.

The main difference between the two types is in the rule for definite assignment of them.

When we use the out parameter, The program calling the function need not assign a value to the out parameter before making the call to the function. The value of the out parameter has to be set by the function before returning the value.

Continued...

Multiple session updating the application variable at same time

Hi,

Many a times we want to keep some values in our application, which should be available Application Wide. We normally keep these values in the application variables. This is very handy and fast to use.

One of the examples of use of Application Variable that I normally use is a Boolean value describing if the application is running locally or Live (Production). The value is retrieved in the Application_start event from the web.config file. This is very handy as at many point in the application I keep a check on the work to be done based on this value. And I do not have to refer to the config file all the time to know if the application is running locally or on production.

Writing and reading to an application variable is very simple. We can write to an application variable like this.
Application["Local"] = false;

Continued...

Asp.Net 2.0 referring to another page, user control with the help of Reference tag

Hi,

In Asp.net 2.0  if we want to create the object of another page  (in the same application) then we can not do it. We get a compiler error in this case. The reason is that each page is compiled into an assembly (We can also make the directory to be compiled in the same assembly). Hence the two pages might not be in the same assembly. And hence we are not able to create the object of another page in the same web application in another page (As they will not be in the same assembly).

But many a times we want to create the object of another page in the code behind class. I know we can use a base page (will be kept in App_Code folder) for all class and derive all the pages from that class. Now we can create the object of the page by typecasting the base page. But this will not solve the entire problem. As we will not have all the methods of the individual class.

Continued...

Visual Studio 2008 Orcas changing the default browser and its default size

Hi,

Every one has a different choice when it comes to browser. I personally like Firefox for surfing the net. I should say the number of addin’s available for Firefox are really very good and makes surfing the net and debugging (Javascript) very easy.

When we use Visual Studio and try to debug a Web Application, by default, it uses the IE. Many a times we do not want it use IE but some other browser (Like Firefox).

With Visual Studio 2008 this can be done very easily. To Change the default browser while using View in browser option just right click on the aspx and select “Browse with” context menu. In the next dialogue we can select or also add the browser there. We can also set the default browser for the Visual Studio in there.

Continued...

Finding the Virtual path of the web Application

Hi,

Many a times we want to find the Virtual path of the Web Application. Getting the virtual paths local to server is pretty straight forward Page.ResolveURL("~").

If you require the same in the BLL, then you have to use the System.Web.HttpRuntime.AppDomainAppVirtualPath

Remember if the web application is in the server root then the following command will return “/” and if the web application is not in the root folder then the command will return the path of the root folder without the “/” in the end.

Vikram


Stored Procedure’s Execute Permission for a new SQL Server User

Hi,

In last few days I have been working with SQL Server Users. In My application the user of the Stored Procedures is not the creator (owner) of the Stored Procedures. Hence the user does not have execute permission on any of the Stored Procedures by default.

Of Late due to some reason we have to create many SQL Server user in the application. Whenever we create a new user in the SQL Server (the user account is used for accessing the database), we have to grant execute permission on all the SP’s. Doing this with the enterprise manager can be very troublesome as we have over 300 Stored Procedures.

I have created a small script with the help of which I get a string that gives permission to the new SQL Server User to all the Stored Procedures.

The script is simple.

select 'Grant Execute on ' + name +  ' SQLServerUSERName'
from sysobjects where xtype in ('P')

Continued...

An overview of use of predicate with generic List

Hi

Predicate are type of filter which can filter data based on certain criteria. Predicate is a generic delegate which represents a method that defines a set of criteria to filter records in a generic list.

Lets take an example of a generic list of string.

List<string> strName = new List<string>();

Now let say we want to fetch those data which starts with V. Without predicate we would write something like the code below.
for (int i = strName.Count - 1; i >= 0; i--)

    {

        if (!strName [i].StartsWith("V"))

        {

           strName.RemoveAt(i);

        }

Continued...

Passing ReadOnlyCollection using the AsReadonly method so that user cannot modify the list

Hi,

This was new to me so as always I decided to share with all. The generic List has a method AsReadonly. The methods can be used if you want to pass the list as readonly. The return value of the method is a ReadOnlyCollection.

The ReadOnlyCollection acts as a wrapper around the list. The only difference of a readonlycollection and a list is that a readonlycollection has a wrapper around it which prevents the modification of the collection.

If there are changes made to the underlying collection, the changes will be refelected in the readonly collection.

Let’s say you have a private collection (list) and want to expose it as read only format. This is when this method will be useful.

Vikram


Asp.Net 2.0 Page Element attributes and there meaning

Hi,

In asp.Net 2.0 there are many attributes in the page tag itself. Each attribute has a special meaning to it. These attributes are defined in the page so that we can specify them for specific pages. Most of them are also defined globally so that we do not have define them in the page.

Here is a list of attributes of the Page Tag.

asyncTimeout – This is an optional attribute to define the timeout for the asynchronous handler during asynchronous processing of the page. The default value is 45 sec.

autoeventWireup – This is also an optional attribute that defines if the events in the page are automatically enabled. The default value is true. This means

if we define a Page_load(with same signature) method in the page class, the event will be automatically be attached with page load method.

Continued...

String class reverse function and extension method

Hi,

One of the most basic functions that I would like to add with the help of the new extension method in dot net 3.5 is the reverse method in the string class. Many a time we want to reverse the character in the string. Currently we do not have any inbuilt method in the framework to reverse the character in a string.

Yes till now we had to work with a static method to reverse the string, but I would love to have this functionality in the string class itself. Here is the implementation of the same.

public static void Reverse(this string strObj)

{

    char[] characters = strObj.ToCharArray();

    Array.Reverse(characters);

    strObj = new string(characters);

}

Continued...

Source code of Dot net framework released by Microsoft with VS 2008 and Dot Net Framework 3.5
Hi,

What a news from Microsoft. They have decided to provide the source code of the dot net frame work class library. The source code will be provided with the final release of the VS 2008 and Dot net framework 3.5. The source code is provided under the Microsoft reference Licence. You can read the full post here

I know we can see the code using reflector, but the ability to debug with the source code will be just great. Think how great it would be to be able to press F11 (Step Into) at the Gridview.databind() and see whats happening inside the databind method.

I am sure this will be loads of fun for most of the developer like me. Cant wait to get my hands on this one.

Vikram

Logging the exception of the Asp.Net application with the help of HttpModule

Hi,

One of the most critical aspect of and asp.net application is exception handling. When an application is there live on the web there can be an exception happening. These exception needs to be logged so that they can be rectified later.

There are many inbuilt ay in which this can be done. Like we can handle the exception at page level, or at the application level or even better create a simple reusable module that can be used in multiple applications.

In this post I will show how we can log the exception in an application. There are three prominent places where we can log the exception.

1 In a text file (or in XML format)

2 In a Database (I know text file is also a database but I meant a RDBMS)

Continued...

Session_End and mysttries on when does it fires in Asp.Net

Hi,

Following my post on few interesting things about session in Asp.Net many people asked me about the Session_End event. You can read the earlier post here.

Many people have asked me on exactly what are the reason for which the Session_End event fires. So I thought I would write a post on the same.

Continued...

Creational design Pattern – Implementing Singleton using Dot Net

Hi,

Singleton in one of the most important of the creational design pattern. Lets start with what is a creational design pattern. Creational design pattern are design pattern which are related with the creating of objects. They define the design for the creation of an object for various usage.

[Note: you can check this previous post of mine on why to use design patterns.
http://www.vikramlakhotia.com/A_word_about_Design_Pattern.aspx ]

Continued...
 
Copyright © 2006 - 2008 Vikram Lakhotia