Tuesday, September 27, 2016

How to set dropdown value by text using jquery

This is just a quick post to show how to set dropdown value by text using jquery.

This is a method that works based on the text of the option, not the index.

 
$("#YourDropDownId option").each(function() {
  if($(this).text() == TextToBeDisplayOrSelected) {
    $(this).attr('selected', 'selected');            
  }                        
});


Special Thanks To : 

Thursday, July 2, 2015

How to get image URL via C# from site-core

This is just a quick post to show how to get image URL via code behind C#.

This is mostly useful when you are binding children items to a repeater or returning image URL in a JSON web-service.

 public static string GetImageURL(Item currentItem)  
 {  
      string imageURL = string.Empty;  
      Sitecore.Data.Fields.ImageField imageField = currentItem.Fields["Image"];  
      if (imageField != null && imageField.MediaItem != null)  
      {  
       Sitecore.Data.Items.MediaItem image = new Sitecore.Data.Items.MediaItem(imageField.MediaItem);  
       imageURL = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(image));  
      }  
 return imageURL;  
 }  


Special Thanks To : 

Thursday, March 12, 2015

HTML Button onserverclick fired twice in ASP.NET UpdatePanel

Old Code:
 

New Code:
Just change button type to button from submit and issue is resolved.

Tuesday, June 16, 2009

To Create a DropDownList from an ENUM

You have an 'Enum' defined as follows:
public enum CompanyAddressType
{
Unknown = 0,
Primary = 1,
Warehouse = 2,
Distribution_Center = 3,
Cross_Dock = 4
}


You want to iterate through the list and put the data into an asp.net DropDownList.

Here is the simple code:


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[] names = Enum.GetNames(typeof (CompanyAddressType));
var values = (CompanyAddressType[]) Enum.GetValues(typeof (CompanyAddressType));
for (int i = 0; i < names.Length; i++)
{
DropDownListCompanyAddressType.Items.Add(new ListItem(names[i], values.ToString()));
}
}
}

There are probably easier ways to do it, but this works.


Use the tips!

Saturday, May 23, 2009

ஜிமெயில் ஷார்ட் கட் கீகள்


உங்களுடைய ஜிமெயில் அக்கவுண்ட்டை மவுஸ் கொண்டு செலுத்துவதற்குப் பதிலாக கீ போர்டு ஷார்ட் கட் கீகள் மூலம் செயல்படுத்தலாம். இந்த கீ போர்டு ஷர்ர்ட் கட் கீகளைப் பயன்படுத்துவதனால் நம் நேரம் மிச்சமாகிறது. மேலும் கீ போர்டிலிருந்து கைகளை எடுக்காமல் விரைவாக நம்மால் செயல்பட முடியும்.

இதோ சில ஷார்ட் கட் கீகள்:

F : கீயை மட்டும் அழுத்தினால் இமெயில் செய்தியை அடுத்ததற்கு பார்வேர்ட் செய்திட முடியும்.

/: சர்ச் பாக்ஸில் உங்கள் கர்சரை நகர்த்த

Shift+l : இமெயில் மெசேஜைப் படித்ததாக குறியீடு செய்வதற்கு

Shift+u : இமெயில் மெசேஜைப் படிக்காததாகக் குறியிட

r : மெயிலை அனுப்பியவருக்கு பதில் அனுப்ப.

u : உங்களுடைய இமெயில் அக்கவுண்ட்டை ரெப்ரெஷ் செய்து லேட்டஸ்டாக வந்த இமெயில் மெசேஜை காண

a : அனைத்து மெயில் பெற்றவர்களுக்கும் பதில் அனுப்ப

ctrl+c
: அப்போதைய இமெயிலை ட்ராப்டாக சேவ் செய்திட

Z : முந்தைய செயல்பாட்டை கேன்சல் செய்திட

? : கீ போர்டு ஷார்ட் கட் கீகள் குறித்த உதவிக் குறிப்புகளைக் காட்ட

c : புதிய இமெயில் மெசேஜ் ஒன்றை எழுதிட

! : இமெயில் மெசேஜ் ஒன்றை ஸ்பாம் மெயிலாகக் குறிப்பிட

p : தற்போதைய மெயிலுக்கு முன் உள்ள மெயிலுக்குச் செல்ல

. : வெறும் புள்ளி அடித்தால் கூடுதலான ஆப்ஷன்ஸ் காட்டப்படும்.

Esc : கர்சரை தற்போதைய பீல்டிலிருந்து நகர்த்தும்.

இந்த பதிவினை படிக்கும் நீங்கள் மறக்காமல் உங்கள் கருத்துகளை என்னிடம் தெரிவிக்கலாம். உங்கள் கருத்துகளுக்காக காத்திருக்கும் நண்பன் - ரங்கோலி.

Tuesday, May 12, 2009

SQL SERVER – How to Drop Primary Key Contraint from a Table

First, we will create a table that has primary key. Next, we will drop the primary key successfully using the correct syntax of SQL Server.

CREATE TABLE Table1(
Col1 INT NOT NULL,
Col2 VARCHAR(100)
CONSTRAINT PK_Table1_Col1 PRIMARY KEY CLUSTERED (
Col1 ASC)
)
GO

Second, try to drop the primary key constraint using following lines.

/* For SQL Server/Oracle/MS ACCESS */
ALTER TABLE Table1
DROP CONSTRAINT PK_Table1_Col1
GO
/* For MySql */
ALTER TABLE Table1
DROP PRIMARY KEY
GO


Use the tips!!!

Thursday, April 23, 2009

Java Script : 'toFixed' Math function to format number

<div style="text-align: justify;">We can use 'toFixed()' function in math to format a number upto required decimal places. The value we get is after rounding the number upto the decimal place required. This function is frequently used in java script. </div>

Here is the sample syntax.
my_val.toFixed(4)
my_val is the variable which stores the number. Here we are formatting the number upto 4 decimal places.

Let us try with some examples with different number values.
var my_val=11.257;
document.write (my_val.toFixed(2)); // output 11.26

var my_val=11.25;
document.write (my_val.toFixed(1)); // output 11.3

var my_val=11.978;
document.write (my_val.toFixed(4)); // output 11.9780

Use the tips!

Tuesday, March 31, 2009

Time Management

Time Management

In my profile, I mentioned as one of my strength is "Goal Setting". What is goal setting? We should plan our Day,Week & Month well before. As we plan we could achieve our goals. Just planning alone will not lead to complete our goals, we should implement it as per our plan. Time is most important here. If you plan half an hour for a job, you should try to finish it as you planned. First time it may not be possible, but when you practice it in your day today activities, it becomes your routine. After some time, you could finish it even before time.

Day Plan :-
  1. Create a simple "To do" list for that particular day
  2. This simple "To do list" will help us to identify the list of items to be completed in that particular day.
  3. List to be prepared as priority, and we could give reason for doing them in priority
  4. A timeline for getting them done, and then printing this simple list and posting it for reminders.
  5. This reminders we could set in our outlook.


Week Plan :-
  1. Write down appointments, classes, training and meetings on a log book or chart.
  2. If you are more visual, sketch out your schedule
  3. First thing in the morning, check what's ahead for the day
  4. Always go to sleep knowing you're prepared for tomorrow


Long term plan :-
  1. Use a monthly chart so that you can plan ahead.
  2. Long term planners will also serve as a reminder to constructively plan time for yourself


All the above can be done for home also... not a big deal right !!

Try for a day plan... reminders.... updates.! You will realise the change on you and your work and also how quick you reach home when you plan your day.

Happy Timing!

Corporate Dress Code

Corporate Dress Code

Corporate dressing is a powerful tool in the office space. The manner in which you present yourself projects not only your personality but the image of the company too. Appropriate dress and grooming has a profound impact on co-workers as well as external customers.

Dress Code Male:
- Do’s

1. Half /Full sleeve shirt with Tie
2. Black/Brown Shoes

- Dont’s

1. Loud Design/Colour Shirts
2. Sports Shoes
Dress Code Female:
- Do’s

1. Salvar /Saree’s
2. Black/ Brown - Shoes / Chappal

- Dont’s

1. Tight Dresses and Sleeveless tops.
2. Jeans Pants, t-shirts with logos / Letters
3. Wearing too much Jewellery
4. Noisy bracelets, Bangles
Dress Down Days :-
Do’s - Casuals wrinkle-free, in good repair, and pulled together with Unifying elements like matching belts and shoes.

Happy Dresssing!

Wednesday, March 25, 2009

WCF Performance: Making your service run 3 times faster

Wisely changing WCF defaults can yield a significant improvement in your service performance. The exact changes need to be made and their exact effect are dependent in the scenario. The example below how to speed up a certain service 3 times faster.
Read more at http://webservices20.blogspot.com/2009/01/wcf-performance-gearing-up-your-service.

Happy Coding!

Wednesday, March 4, 2009

Interview Question WCF - Part 1

  1. What is WCF?
    Windows Communication Foundation (WCF) is an SDK for developing and deploying services on Windows. WCF provides a runtime environment for services, enabling you to expose CLR types as services, and to consume other services as CLR types.

    WCF is part of .NET 3.0 and requires .NET 2.0, so it can only run on systems that support it.

    Windows Communication Foundation is Microsoft's unified programming model for building service-oriented applications with managed code. It extends the .NET Framework to enable developers to build secure and reliable transacted Web services that integrate across platforms and inter-operate with existing investments.

    Windows Communication Foundation combines and extends the capabilities of existing Microsoft distributed systems technologies, including Enterprise Services, System.Messaging, Microsoft .NET Remoting, ASMX, and WSE to deliver a unified development experience across multiple axes, including distance (cross-process, cross-machine, cross-subnet, cross-intranet, cross-Internet), topologies (farms, fire-walled, content-routed, dynamic), hosts (ASP.NET, EXE, Windows Presentation Foundation, Windows Forms, NT Service, COM+), protocols (TCP, HTTP, cross-process, custom), and security models (SAML, Kerberos, X509, username/password, custom).

  2. What is service and client in perspective of data communication?
    A service is a unit of functionality exposed to the world. The client of a service is merely the party consuming the service.

  3. What is endpoint in WCF? or What is three major points in WCF?
    Every service must have Address that defines where the service resides, Contract that defines what the service does and a Binding that defines how to communicate with the service. In WCF the relationship between Address, Contract and Binding is called Endpoint. The Endpoint is the fusion of Address, Contract and Binding.

    1) Address ---> Specifies the location of the service which will be like http://Myserver/MyService.Clients will use this location to communicate with our service.

    2) Contract ---> Specifies the interface between client and the server.It's a simple interface with some attribute.

    3) Binding ---> Specifies how the two paries will communicate in term of transport and encoding and protocols.

  4. What is binding and how many types of bindings are there in WCF?
    A binding defines how an endpoint communicates to the world. A binding defines the transport (such as HTTP or TCP) and the encoding being used (such as text or binary). A binding can contain binding elements that specify details like the security mechanisms used to secure messages, or the message pattern used by an endpoint.

    WCF supports nine types of bindings.

    1. Basic binding

    Offered by the BasicHttpBinding class, this is designed to expose a WCF service as a legacy ASMX web service, so that old clients can work with new services. When used by the client, this binding enables new WCF clients to work with old ASMX services.

    2. TCP binding

    Offered by the NetTcpBinding class, this uses TCP for cross-machine communication on the intranet. It supports a variety of features, including reliability, transactions, and security, and is optimized for WCF-to-WCF communication. As a result, it requires both the client and the service to use WCF.

    3. Peer network binding

    Offered by the NetPeerTcpBinding class, this uses peer networking as a transport. The peer network-enabled client and services all subscribe to the same grid and broadcast messages to it.

    4. IPC binding

    Offered by the NetNamedPipeBinding class, this uses named pipes as a transport for same-machine communication. It is the most secure binding since it cannot accept calls from outside the machine and it supports a variety of features similar to the TCP binding.

    5. Web Service (WS) binding

    Offered by the WSHttpBinding class, this uses HTTP or HTTPS for transport, and is designed to offer a variety of features such as reliability, transactions, and security over the Internet.

    6. Federated WS binding

    Offered by the WSFederationHttpBinding class, this is a specialization of the WS binding, offering support for federated security.

    7. Duplex WS binding

    Offered by the WSDualHttpBinding class, this is similar to the WS binding except it also supports bidirectional communication from the service to the client.

    8. MSMQ binding

    Offered by the NetMsmqBinding class, this uses MSMQ for transport and is designed to offer support for disconnected queued calls.

    9. MSMQ integration binding

    Offered by the MsmqIntegrationBinding class, this converts WCF messages to and from MSMQ messages, and is designed to interoperate with legacy MSMQ clients.

    For WCF binding comparison, see http://www.pluralsight.com/community/blogs/aaron/archive/2007/03/22/46560.aspx

  5. What is contracts in WCF?
    In WCF, all services expose contracts. The contract is a platform-neutral and standard way of describing what the service does.

    WCF defines four types of contracts.

    1. Service contracts

    Describe which operations the client can perform on the service.

    2. Data contracts

    Define which data types are passed to and from the service. WCF defines implicit contracts for built-in types such as int and string, but we can easily define explicit opt-in data contracts for custom types.

    3. Fault contracts

    Define which errors are raised by the service, and how the service handles and propagates errors to its clients.

    4. Message contracts

    Allow the service to interact directly with messages. Message contracts can be typed or untyped, and are useful in interoperability cases and when there is an existing message format we have to comply with.

  6. Where we can host WCF services?
    Every WCF services must be hosted somewhere. There are three ways of hosting WCF services. They are
    1. IIS
    2. Self Hosting
    3. WAS (Windows Activation Service)

    For more details see http://msdn.microsoft.com/en-us/library/bb332338.aspx

  7. What is address in WCF and how many types of transport schemas are there in WCF?
    Address is a way of letting client know that where a service is located. In WCF, every service is associated with a unique address. This contains the location of the service and transport schemas. WCF supports following transport schemas

    1. HTTP
    2. TCP
    3. Peer network
    4. IPC (Inter-Process Communication over named pipes)
    5. MSMQ

    The sample address for above transport schema may look like

    http://localhost:81
    http://localhost:81/MyService
    net.tcp://localhost:82/MyService
    net.pipe://localhost/MyPipeService
    net.msmq://localhost/private/MyMsMqService
    net.msmq://localhost/MyMsMqService

  8. What is the difference WCF and Web services?
    1. Web services can only be invoked by HTTP. While Service or a WCF component can be invoked by any protocol and any transport type.

    2. Second web services are not flexible. But Services are flexible. If you make a new version of the service then you need to just expose a new end point. So services are agile and which is a very practical approach looking at the current business trends.

  9. How can we host a service on two different protocols on a single server?
    Let’s first understand what this question actually means. Let’s say we have made a service and we want to host this service using HTTP as well as TCP. You must be wondering why to ever host services on two different types of protocol. When we host a service it’s consumed by multiple types of client and it’s very much possible that they have there own protocol of communication. A good service has the capability to downgrade or upgrade its protocol according the client who is consuming him.
    Let’s do a small sample in which we will host the ServiceGetCost on TCP and HTTP protocol.

    Once we are done the server side coding its time to see make a client by which we can switch between the protocols and see the results. Below is the code snippet of the client side for multi-protocol hosting

  10. How does WCF work?
    Follows the 'software as a service' model, where all units of functionality are defined as services.

    A WCF Service is a program that exposes a collection of Endpoints. Each Endpoint is a portal (connection) for communication with either clients (applications) or other services.

    Enables greater design flexibility and extensibility of distributed systems architectures.

    A WCF application is represented as a collection of services with multiple entry points for communications

  11. What are the main components of WCF?
    - Service: The working logic or offering, implemented using any .Net Language(C#).
    - Host: The environment where the service is parked. E.g. exe, process, windows service
    - Endpoints: The way a service is exposed to outside world.

    Following figure shows us all the core components.



  12. Explain transactions in WCF
    Transactions in WCF allow several components to concurrently participate in an operation. Transactions are a group of operations that are atomic, consistent, isolated and durable. WCF has features that allow distributed transactions. Application config file can be used for setting transaction timeouts.

  13. What are different isolation levels provided in WCF?

    The different isolation levels:

    1. READ UNCOMMITTED: - An uncommitted transaction can be read. This transaction can be rolled back later.
    2. READ COMMITTED :- Will not read data of a transaction that has not been committed yet
    3. REPEATABLE READ: - Locks placed on all data and another transaction cannot read.
    4. SERIALIZABLE:- Does not allow other transactions to insert or update data until the transaction is complete.

  14. Explain transactions in WCF
    Transactions in WCF allow several components to concurrently participate in an operation. Transactions are a group of operations that are atomic, consistent, isolated and durable. WCF has features that allow distributed transactions. Application config file can be used for setting transaction timeouts.

  15. How do I serialize entities using WCF?
    LINQ to SQL supports serialization as XML via WCF by generating WCF serialization attributes and special serialization specific logic during code-generation. You can turn on this feature in the designer by setting serialization mode to 'Unidirectional'. Note this is not a general solution for serialization as unidirectional mode may be insufficient for many use cases.


Happy Interview!!!

Tuesday, February 24, 2009

Online convertion tools from C# to VB.NET and VB.NET to C#

Online convertion tools for C# to VB.NET and VB.NET to C#.

Use the following tools for converting C# code to VB.NET code and from VB.NET to C# code. Its very efficient and great tools available as of now. These tools are more reliable even for .Net 3.5 except for LINQ.

Simply paste in your C# code , and this free utility will automatically convert it to its equivalent in VB.NET.
http://www.developerfusion.com/tools/convert/csharp-to-vb/

Simply paste in your VB.NET code , and this free utility will automatically convert it to its equivalent in C#.
http://www.developerfusion.com/tools/convert/vb-to-csharp/

Happy Coding...

Tuesday, February 17, 2009

Interview Question asp.net 3.5 - Part 1

What do you mean by three-tier architecture?
The three-tier architecture was comes into existence to improve management of code and contents and to improve the performance of the web based applications. There are mainly three layers in three-tier architecture. the are define as follows
  1. Presentation
  2. Business Logic
  3. Database
1. First layer- Presentation contains mainly the interface code, and this is shown to user. This code could contain any technology that can be used on the client side like HTML, JavaScript or VBScript etc.

2. Second layer - is Business Logic which contains all the code of the server-side .This layer have code to interact with database and to query, manipulate, pass data to user interface and handle any input from the UI as well.

3. Third layer-Data represents the data store like MS Access, SQL Server, an XML file, an Excel file or even a text file containing data also some additional database are also added to that layers.

Do not use design patterns in any of the following situations.


When the software being designed would not change with time.
When the requirements of the source code of the application are unique.

If any of the above applies in the current software design, there is no need to apply design patterns in the current design and increase unnecessary complexity in the design.

When to use Design Patterns
Design Patterns are particularly useful in one of the following scenarios.

* When the software application would change in due course of time?

* When the application contains source code that involves object creation and event notification?

The following are some of the major advantages of using Design Patterns in software development.
  1. Flexibility
  2. Adaptability to change
  3. Reusability
What are Design Patterns?
A Design Pattern essentially consists of a problem in a software design and a solution to the same. In Design Patterns each pattern is described with its name, the motivation behind the pattern and its applicability.

According to MSDN, "A design pattern is a description of a set of interacting classes that provide a framework for a solution to a generalized problem in a specific context or environment. In other words, a pattern suggests a solution to a particular problem or issue in object-oriented software development.

Happy Interview...!

Thursday, February 12, 2009

உலகின் முதல் இணையதளம்

செவ்வாய் கிரகத்தில் தெரியாது. ஆனால் பூமியில் டிசம்பர் 1990 கணக்குப்படி ஒரே ஒரு இணையதளம் தான் இருந்தது. அதன் விலாசம் info.cern.ch அதற்கு சொந்தக்காரர் www-வை அதாவது html-ஐ கண்டு பிடித்த Tim Berners-Lee ஆவார்.

இன்றைக்கு வெப் 2.0 வெப் 3.0 வென போய்கொண்டிருக்கின்றோம். ஆனாலும் அன்றைக்கு அவர் முதன்முதலாய் நெய்த அந்த வலைப்பக்கத்தை இன்றைக்கும் பத்திரமாய் வைத்திருக்கின்றார்கள். நீங்கள் கீழ்கண்ட சுட்டிபோய் அதை பார்க்கலாம்.
http://www.w3.org/History/19921103-hypertext/hypertext/WWW/TheProject.html
1990-ல் இவ்வெளிய பக்கத்தை உருவாக்க உங்களுக்குத் தெரிந்திருந்தால் நீங்கள் தான் பூமிப்பந்தை இணைய வலையில் சிக்கவைத்த ஜீனியஸ் சிலந்தியாய் இருந்திருப்பீர்கள்.

இந்த மே மாத கணக்குப்படி இணைய உருண்டையின் மொத்த இணையதளங்களின் எண்ணிக்கை என்ன தெரியுமா? 168,408,112 அபாரமானமான வளர்ச்சிதான். இத்தனை வெப்தளங்கள் உருவாக பலகாரணங்கள் சொல்லப்பட்டாலும் ஒரு முக்கிய காரணமாய் அமைந்தது கூகிளின் அட்சென்ஸ் (Google Adsense) என்றால் மிகையாகாது.

தங்கள் இணையதளங்களில் ஓடும் விளம்பரங்களை கிளிக்கினால் மாதம் தோறும் காசோலை வீடு தேடி வரும் என்றதும் மெக்கானிக்கல், சிவில் மாணவன் கூட இணையதளம் தொடக்கினான். பல வெப்வித்தைகளை காட்டிசட்டம் சட்டமாய் விளம்பரங்களைப் போட்டு. இப்படி ஆடை அணிகலன்களோடும் நிர்வாணமாயும் ஆயிரம் ஆயிரம் தளங்கள்.

இத்தனை வெற்றிகரமான கூகிளின் ஆட்சென்ஸ் புராஜெக்ட்டை முன்னின்று நடத்தியவர் ஒரு இந்தியர் என்பது நமக்கெல்லாம் பெருமை. அவர் பெயர்கோகுல் ராஜாராம் (Gokul Rajaram). 2003-ல் கூகிளின் இந்த நுட்பம் வெளிவந்தபின்பு தான் கூகிளுக்கு காசு கொட்டோ கொட்டென கொட்டத்தொடங்கியது.அப்புறம் இணைய காட்டுக்கு இன்றுவரை கூகிள் தான் ராஜா.

ராஜாராம் கான்பூர் IIT யில் B.Tech முடித்து பின் MIT Sloan School of Management-ல் M.B.A-யும் M.S. in Computer Science-ம் முடித்தவர். ராஜாராம்பழைய நினைவுகளை சொலலும்போது "When we started adsense, it was just me and four engineers,” “The night before we launched, Sergey spent five hours with me testing the system and pointing out bugs." என்கின்றார் மறக்க இயலாத நினைவுகளாக. இணையத்தின் போக்கையே மாற்றிய நாளல்லவா அது. இங்கு அவர் கூறும்"செர்ஜி" கூகிளை நிறுவிய நிறுவனர்களில் ஒருவர் ஆவார்.

ஆனாலும் கோகுல் ராஜாராம் இன்றைக்கு Xoogler ஆகிவிட்டார். அதாவது மில்லியன்களை சம்பாதித்து விட்டு இனி தானே தனக்காக உழைக்கப்போவதாக chailabs.com தொடங்கியிருக்கிறார். அதன் விவரங்களெல்லாம் இப்போதைக்கு ரகசியமே. எதாவது வியப்பாய் சீக்கிரமாய்கொண்டு வருவார் என எல்லோரும் எதிர்பார்க்கின்றார்கள்.

இன்றைக்கு Google Adsense-ன் நிலமை அவ்வளவு பிரகாசமாய் இல்லை. மைஸ்பேஸ் சிறுவர்கள் கும்பலை நம்பி மில்லியன்களை கூகிள் செலவழித்துகையை தானே சுட்டுக் கொண்டிருக்கிறது. வருமானமும் கம்மி. கொஞ்சகாலமாய் இன்னோவேசனே இல்லை. இப்படி அநேக கம்ப்ளெயின்ட்கள். பலமுக்கிய googler-கள் வேறு xoogler-கள் ஆகிக் கொண்டிருக்கின்றனர். இப்படிதொடர்ச்சியாய் மாற்றங்கள், உலகில் அது மட்டும்தானே மாறாதது. x-googler.

நன்றி : பிகேபி வலைப்பதிவு

நல்ல பதிவு பலரையும் சென்றடைய மறக்காமல் உங்கள் கருத்துகளை அழகாய் சொல்லிடு போடுங்க.

Tuesday, January 6, 2009

Depositfiles Hack - No More "Wait 60 Seconds"!!!

Firstly, you need to be using a Firefox / Mozilla browser.

1. Copy the Depositfiles download URL and paste it on your Browsers Address Bar, press Enter..

2. Now click on "Free Downloading".

3. Next, as soon as the COUNTDOWN Begins...

4. Goto your browsers menu bar and click on VIEW ---> PAGE STYLE ---> NO STYLE

5. Now the Download Button will appear... click on it and start downloading....No waiting!

Thanks : Katforum

Happy Downloading...!

Tuesday, December 30, 2008

Thursday, December 25, 2008

C# array in descending or reverse order

How do you sort a C# array in descending or reverse order? A simple way is to sort the array in ascending order, then reverse it:
int[] intArray = new int[] { 3, 1, 4, 5, 2 };
Array.Sort<int>( intArray );
Array.Reverse( intArray );
Of course, this is not efficient for large arrays.

A better approach is to create a custom Comparer. Following is a nice generics class that will sort an array in descending order. Note that the object type must be comparable (inherit from IComparable) as any useful class should.

Here’s a simple web application to test it:

<%@ Page Language="C#" AutoEventWireup="true" Codebehind="SortSample.aspx.cs" Inherits="SampleApplication.SortSample" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Sort Ascending /Descending Order by Generic</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;

namespace SampleApplication.
{
public partial class SortSample: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int[] intArray = new int[] { 3, 1, 4, 5, 2 };
char[] charArray = new char[] { 'r', '1', 'f', 'c', 'x' };
string[] stringArray = new string[] { "array item 1", "array item 2", "array item 3", "array item 4", "array item 5" };

ArraySorter<int>.SortDescending(intArray);
ArraySorter<char>.SortDescending(charArray);
ArraySorter<string>.SortDescending(stringArray);

BindDropDownList(DropDownList1, intArray);
BindDropDownList(DropDownList2, charArray);
BindDropDownList(DropDownList3, stringArray);
}

private static void BindDropDownList(BaseDataBoundControl ddl, Array arr)
{
if(ddl !=null && arr !=null && arr.Length>0)
{
ddl.DataSource = arr;
ddl.DataBind();
}
}
static public class ArraySorter<T> where T : IComparable
{
static public void SortDescending(T[] array)
{
Array.Sort<T>(array, s_Comparer);
}

static private readonly ReverseComparer s_Comparer = new ReverseComparer();

private class ReverseComparer : IComparer<T>
{
public int Compare(T object1, T object2)
{
return -((IComparable)object1).CompareTo(object2);
}
}
}

}
}

I hope it will help you in someway.

Happy Coding!!!

Saturday, December 20, 2008

Design Pattern - Abstract Factory Pattern

Today I'm going to write about one of the most popular patterns in the design patterns world - the abstract factory.

You can read my previous posts about design patterns here:
An abstract factory provides an interface for creating families of related objects without specifying their concrete classes.

The abstract factory dictates which products the concrete factories will produce. Each concrete factory can build different products of different types.

The only way to get the products by the client is through the factory which isolate the products definition and creation. Object creation has been abstracted and there is no need for hard-coded class names in the client code.

For an example, take a real-world demonstrates the Factory method offering flexibility in creating different documents. The derived Document classes Report and Resume instantiate extended versions of the Document class. Here, the Factory Method is called in the constructor of the Document base class.

using System;
using System.Collections.Generic;
using System.Text;

namespace DesignPatternConsole
{
/// <summary>
/// The 'Product' abstract class
/// </summary>
abstract class Page
{
}


/// <summary>
/// A 'ConcreteProduct' class
/// </summary>
class SkillsPage : Page
{
}

/// <summary>
/// A 'ConcreteProduct' class
/// </summary>
class EducationPage : Page
{
}


/// <summary>
/// A 'ConcreteProduct' class
/// </summary>
class ExperiencePage : Page
{
}


/// <summary>
/// A 'ConcreteProduct' class
/// </summary>
class IntroductionPage : Page
{
}


/// <summary>
/// A 'ConcreteProduct' class
/// </summary>
class ResultsPage : Page
{
}


/// <summary>
/// The 'Creator' abstract class
/// </summary>
abstract class Document
{
private List<Page> _pages = new List<Page>();

// Constructor calls abstract Factory method
public Document()
{
this.CreatePages();
}

public List<Page> Pages
{
get { return _pages; }
}

// Factory Method
public abstract void CreatePages();
}

/// <summary>
/// A 'ConcreteCreator' class
/// </summary>
class Resume : Document
{
// Factory Method implementation
public override void CreatePages()
{
Pages.Add(new SkillsPage());
Pages.Add(new EducationPage());
Pages.Add(new ExperiencePage());
}
}

/// <summary>
/// A 'ConcreteCreator' class
/// </summary>
class Report : Document
{
// Factory Method implementation
public override void CreatePages()
{
Pages.Add(new IntroductionPage());
Pages.Add(new ResultsPage());
}
}

class AbstractFactory
{
/// <summary>
/// Entry point into console application.
/// </summary>
static void Main()
{
// Note: constructors call Factory Method
Document[] documents = new Document[2];
documents[0] = new Resume();
documents[1] = new Report();

// Display document pages
foreach (Document document in documents)
{
Console.WriteLine("\n" + document.GetType().Name + "--");
foreach (Page page in document.Pages)
{
Console.WriteLine(" " + page.GetType().Name);
}
}

// Wait for user
Console.ReadKey();
}
}
}

Output :

The benefits of using the pattern are the isolation of concrete classes, it makes it easy to exchange product families and it makes the products consistent.

The drawback of the pattern is that the support of new products is difficult.

Happy Coding!!!

Design Pattern - Singleton

Before we move to Singleton pattern, first we should know what is instantiation and how it will play main role in Singleton.

Please refer my previous post for basic information about Design Pattern if you needs.

Instantiation means creating an object using a class as a template. There are two approaches to instantiation:
  • Lazy instantiation
  • Eager instantiation

Lazy instantiation : a class is not instantiated until a request is made via the Singleton.Instance() method.
if (singleton == null)
{
singleton = new Singleton(); // lazy instantiation
Console.WriteLine ("Singleton instantiated");
}

This code is quite simple. If singleton is null, then the Singleton object has not yet been instantiated. And, if not, it is instantiated with the new operator. This is only done once; because, the next time the code is called, singleton will not be null.

Eager instantiation is still lazy, it will run the initializers whenever the class is instantiated or another static member is accessed.

public sealed class Singleton
{

//private static Singleton singleton;
private static readonly Singleton singleton = new Singleton(); // eager instantiation

static Singleton()
{
Console.WriteLine ("Singleton instantiated");
}

private Singleton() {} // private constructor

public static Singleton GetInstance()
{
//if (singleton == null)
//{
// singleton = new Singleton();
// Console.WriteLine ("Singleton instantiated");
//}
return singleton;
}
}

The only differences between this eager code and the previous lazy example is that Singleton is instantiated in the static initializer instead of in the Singleton.Instance() method; and, there is a static constructor. However, this implementation is thread safe.


Now we will move to singleton.

Singleton is a design pattern used to restrict the instantiation of a class to one object. It is one of the most used and well know design patterns in programming.

For an example, you may need a class that will contain the user information across the system, there is no need to create several instances of this class. The explanation of this will be given in this little sample below:

Step 1. DesignPatternTest.aspx

<%@ Page Language="C#" AutoEventWireup="true" Codebehind="DesignPatternTest.aspx.cs"
Inherits="DesignPatternTest.SingletonSample" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Singleton</title>
</head>
<body>
<form id="form1" runat="server">
<div>
See the above Singleton output
</div>
</form>
</body>
</html>

Step 2. DesignPatternTest.aspx.cs
using System;

namespace DesignPatternTest
{
public partial class SingletonSample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Constructor is protected
// Prevented from using 'new' keyword
Singleton s1 = Singleton.Instance();
Singleton s2 = Singleton.Instance();

if (s1 == s2)
Response.Write("s1 & s2 are the same instance");

s1.x = 100;
Response.Write("<br>s1.x=" + s1.x);

s2.x = 200;
Response.Write("<br>s2.x=" + s2.x);

// Updates to x are updating same instance
Response.Write("<br>s1.x=" + s1.x);
Response.Write("<br>s2.x=" + s2.x);

}
}

public class Singleton
{
// Variable
public int x = 0;

// Fields
private static Singleton instance;

// Empty Constructor
protected Singleton() { }

// Methods
public static Singleton Instance()
{
// Uses "Lazy initialization"
if (instance == null)
instance = new Singleton();

return instance;
}
}
}

See the output

Singleton can be used in many situations, for samples.
  • Caches
  • Loggers
  • Thread pools
  • Dialog boxes
  • Device drivers
Last but not least, singleton is a class which permits itself to be instantiated only once.

  • Has a private or protected constructor with no parameters.
  • Has a single, global means of access via a static method.
  • Cannot be subclassed nor instantiated with the new operator.
  • Uses lazy instantiation

Happy Coding!!!

Saturday, December 6, 2008

Highlight Datagrid or GridView row on mouse over in asp.net

To highlight the row and when mouse moves out, the style sheet is switched back to normal.

Use the following two steps to solve this case. This will applicable for both Gridview and Datagrid controls.

Step 1 : Create styles for normal and highlight view of the row.

<style type="text/css">
.normalrow
{
background-color:white;
}
.hightlighrow
{
background-color:#cccccc;
}
</style>
Step 2 : Now add handler for RowCreated event for the grid and add the attributes for onmouseover and onmouseout javascript events.

Following code snippet shows how this has been done.

protected void OnRowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.className='hightlighrow'");
e.Row.Attributes.Add("onmouseout", "this.className='normalrow'");
}
}
Use the technology!!!