Saturday, May 31, 2014

Barish Ka Ye Mousam

Zappmania-Barish-Ka-Mausam

Barish Ka Ye Mousam




Barish Ka Ye Mousam Koch Yaad Dilata Hai

Kisi Kay Saath Honay Ka Ehsaas Dilata Hai

Fiza Bhi Sard Hai Yaadain Bhi Taaza Hai

Ye Mousam Kisi Ka Pyaar Dil May Jagata Hai

Bheegi Hoye Raatain Khamosh Si Baatain

Aisay Main Koch Kaho Tu Her Lafz Madhem Ho Jata Hai

Barsat Ki Hain Bondain, Bondain May Hai Khushbo

Ye Lumha To Dil Ka Ehsaas Chuu Jata Hai

Aisay Main Tum Bhi Keh Do Dil Ki Baat

Ye Mousam Tu Pal Bhar Main Beet Jata Ha,

Barish ka ye mousam kuch yaad dilaata h



Barish Ka Ye Mousam

Samsung Galaxy Mega 6.3 Receiving Android 4.4 KitKat Update

galaxy-mega-6.3 and mega 5.8

Samsung Galaxy Mega 6.3 Receiving Android 4.4 KitKat Update




Samsung is gradually rolling out the Android 4.4 KitKat update for its top-of-the-line Galaxy smartphones and the latest to join the league seems to be the Galaxy Mega 6.3 phablet.

Users in Russia are reporting that the Samsung Galaxy Mega 6.3 is receiving the Android 4.4 KitKat (update) via Kies software, according to Sammobile, with build number I9200XXUDNE4. The report speculates the update should soon be available over-the-air (OTA) for Galaxy Mega 6.3 users in Russia


New features on the Galaxy Mega 6.3 that came with the KitKat update noted by the report includes:


  • faster performance;

  • white status bar icons;

  • better battery life;

  • full-screen mode for album art when playing music;

  • camera shortcut on the lock screen,

  • support for wireless printing and

  • support for setting default messaging and launcher apps.

The Android 4.4 KitKat update for Galaxy Mega 6.3 users outside Russia should also start rolling out over the course of the next few weeks.

Notably, a recent report had suggested that the Galaxy Mega 6.3 was undergoing final KitKat build-testing and should receive the update in June. As the leak seems to be true now, we can expect that the Galaxy Grand 2 and the Galaxy Mega 5.8 will also receive the Android KitKat soon.



Samsung Galaxy Mega 6.3 Receiving Android 4.4 KitKat Update

Sunday, May 25, 2014

गंगा बहती हो क्यूँ - Ganga Behti Ho Kyon


गंगा बहती हो क्यूँ – Ganga Behti Ho Kyon (Bhupen Hazarika)




Performed By: भूपेन हज़ारिका, कविता कृष्णमूर्ति, हरिहरन, शान


आसामी

बिस्तिर्नो पारोरे, ओखोंक्यो जोनोरे

हाहाकार क्सुनिऊ निशोब्दे निरोबे

बुरहा लुइत तुमि, बुरहा लुइत बुआ कियो?

हिन्दी

विस्तार है अपार, प्रजा दोनों पार

करे हाहाकार निःशब्द सदा

ओ गंगा तुम

ओ गंगा बहती हो क्यूँ?


नैतिकता नष्ट हुई, मानवता भ्रष्ट हुई

निर्लज्ज भाव से बहती हो क्यूँ?

इतिहास की पुकार, करे हुंकार

ओ गंगा की धार

निर्बल जन को

सबल-संग्रामी, समग्रोगामी

बनाती नहीं हो क्यूँ?


अनपढ़ जन अक्षरहिन

अनगीन जन खाद्यविहीन

नेत्रविहीन दिक्षमौन हो क्यूँ?

इतिहास की पुकार…


व्यक्ति रहे व्यक्ति केंद्रित

सकल समाज व्यक्तित्व रहित

निष्प्राण समाज को छोड़ती ना क्यूँ?

इतिहास की पुकार…


रुदस्विनी क्यूँ न रहीं?

तुम निश्चय चितन नहीं

प्राणों में प्रेरणा देती ना क्यूँ?

उनमद अवमी कुरुक्षेत्रग्रमी

गंगे जननी, नव भारत में

भीष्मरूपी सुतसमरजयी जनती नहीं हो क्यूँ?

विस्तार है अपार…
गंगा बहती हो क्यूँ – Ganga Behti Ho Kyon (Bhupen Hazarika)

गंगा बहती हो क्यूँ – Ganga Behti Ho Kyon (Bhupen Hazarika)




गंगा बहती हो क्यूँ - Ganga Behti Ho Kyon

Sunday, May 18, 2014

List of Presidents of India

List of Presidents of India (1947-2014)



Below is the list of all Presidents of India from 1947 to 2014.
* Acting President






































































































S.No.
NameTookofficeLeftofficePolitical partyNotes
13Pranab Mukherjee25-Jul-12Till dateIndian National CongressMukherjee held various posts in the cabinet ministry for the Government of India such as Finance Minister, Foreign Minister, Defence Minister and Deputy Chairman of the Planning Commission.
12Pratibha Patil25-Jul-0725-Jul-12Indian National CongressPatil was the first woman to become President of India. She was also the first female Governor of Rajasthan
11A. P. J. Abdul Kalam25-Jul-0225-Jul-07IndependentKalam was a scientist who played a leading role in the development of India's ballistic missile and nuclear weapons programs. Kalam also received the Bharat Ratna.
10Kocheril Raman Narayanan25-Jul-9725-Jul-02IndependentNarayanan served as India's ambassador to Thailand, Turkey, China and United States of America. He received doctorates in Science and Law and was also a chancellor in several universities. He was also the vice-chancellor of Jawaharlal Nehru University.
9Shankar Dayal Sharma25-Jul-9225-Jul-97Indian National CongressSharma was Chief Minister of Madhya Pradesh, and the Indian Minister for Communications. He has also served as the governor of Andhra Pradesh, Punjab and Maharashtra.
8Ramaswamy Venkataraman25-Jul-8725-Jul-92Indian National CongressIn 1942, Venkataraman was jailed by the British for his involvement in the India's independence movement.After his release, he was elected to independent India’s Provisional Parliament as a member of the Congress Party in 1950 and eventually joinedthe central government, where he first served as Minister of Finance and Industry and later as Minister of Defence.
7Giani Zail Singh25-Jul-8225-Jul-87Indian National CongressIn March 1972, Singh assumed the position of chief Minister of Punjab, and in 1980, he became Union Home Minister.
6Neelam Sanjiva Reddy25-Jul-7725-Jul-82Janata PartyReddy was the only Member ofParliament from the Janata Party to get elected from Andhra Pradesh. He was unanimously elected Speaker of the Lok Sabha on 26 March 1977 and relinquished this office on 13 July 1977 to become the 6th President ofIndia.

Basappa Danappa Jatti *11-Feb-7725-Jul-77IndependentJatti was the vice president of India during Ahmed's term of office, and was sworn in as acting president upon Ahmed's death. He earlier functioned as the Chief Minister for the State of Mysore.
5Fakhruddin Ali Ahmed24-Aug-7411-Feb-77Indian National CongressFakhruddin Ali Ahmed served as a Minister before being elected as president. He died in 1977 before his term of office ended, and was the second Indian president to have diedduring a term of office.
4Varahagiri Venkata Giri24-Aug-6924-Aug-74IndependentGiri is the only person to have served as both an acting president and president of India. He was a recipient ofthe Bharat Ratna, and has functioned as Indian Minister of Labour and High Commissioner to Ceylon (Sri Lanka).

Muhammad Hidayatullah *20-Jul-6924-Aug-69IndependentHidayatullah served as the Chief Justice of India, and was a recipient of the Order of the British Empire. He served as acting president until the election of Giri as the President of India.

Varahagiri Venkata Giri *3-May-6920-Jul-69IndependentGiri was appointed as acting president following the death of Hussain. He resigned in a few months to take partin the presidential elections.
3Zakir Hussain13-May-673-May-69IndependentHussain was vice chancellor of the Aligarh Muslim University and a recipient of Padma Vibhushan and Bharat Ratna. He died before his term of office was ended.
2Sarvepalli Radhakrishnan13-May-6213-May-67IndependentRadhakrishnan was a prominent philosopher, writer, a Knight of the Realm and also held the position of vice chancellor of the Andhra University and Banaras Hindu University. Hewas also made a Knight of the Golden Army of Angels by Pope Paul VI.
1Rajendra Prasad26-Jan-5013-May-62Indian National CongressPrasad was the first President of independent India. He was also an independence activist of the Indian Independence Movement. Prasad was the only president to serve for two terms in office.

* Acting President



List of Presidents of India

List of Presidents of India

List of Presidents of India (1947-2014)



Below is the list of all Presidents of India from 1947 to 2014.






































































































S.No.
NameTookofficeLeftofficePolitical partyNotes
13Pranab Mukherjee25-Jul-12Till dateIndian National CongressMukherjee held various posts in the cabinet ministry for the Government of India such as Finance Minister, Foreign Minister, Defence Minister and Deputy Chairman of the Planning Commission.
12Pratibha Patil25-Jul-0725-Jul-12Indian National CongressPatil was the first woman to become President of India. She was also the first female Governor of Rajasthan
11A. P. J. Abdul Kalam25-Jul-0225-Jul-07IndependentKalam was a scientist who played a leading role in the development of India's ballistic missile and nuclear weapons programs. Kalam also received the Bharat Ratna.
10Kocheril Raman Narayanan25-Jul-9725-Jul-02IndependentNarayanan served as India's ambassador to Thailand, Turkey, China and United States of America. He received doctorates in Science and Law and was also a chancellor in several universities. He was also the vice-chancellor of Jawaharlal Nehru University.
9Shankar Dayal Sharma25-Jul-9225-Jul-97Indian National CongressSharma was Chief Minister of Madhya Pradesh, and the Indian Minister for Communications. He has also served as the governor of Andhra Pradesh, Punjab and Maharashtra.
8Ramaswamy Venkataraman25-Jul-8725-Jul-92Indian National CongressIn 1942, Venkataraman was jailed by the British for his involvement in the India's independence movement.After his release, he was elected to independent India’s Provisional Parliament as a member of the Congress Party in 1950 and eventually joinedthe central government, where he first served as Minister of Finance and Industry and later as Minister of Defence.
7Giani Zail Singh25-Jul-8225-Jul-87Indian National CongressIn March 1972, Singh assumed the position of chief Minister of Punjab, and in 1980, he became Union Home Minister.
6Neelam Sanjiva Reddy25-Jul-7725-Jul-82Janata PartyReddy was the only Member ofParliament from the Janata Party to get elected from Andhra Pradesh. He was unanimously elected Speaker of the Lok Sabha on 26 March 1977 and relinquished this office on 13 July 1977 to become the 6th President ofIndia.

Basappa Danappa Jatti *11-Feb-7725-Jul-77IndependentJatti was the vice president of India during Ahmed's term of office, and was sworn in as acting president upon Ahmed's death. He earlier functioned as the Chief Minister for the State of Mysore.
5Fakhruddin Ali Ahmed24-Aug-7411-Feb-77Indian National CongressFakhruddin Ali Ahmed served as a Minister before being elected as president. He died in 1977 before his term of office ended, and was the second Indian president to have diedduring a term of office.
4Varahagiri Venkata Giri24-Aug-6924-Aug-74IndependentGiri is the only person to have served as both an acting president and president of India. He was a recipient ofthe Bharat Ratna, and has functioned as Indian Minister of Labour and High Commissioner to Ceylon (Sri Lanka).

Muhammad Hidayatullah *20-Jul-6924-Aug-69IndependentHidayatullah served as the Chief Justice of India, and was a recipient of the Order of the British Empire. He served as acting president until the election of Giri as the President of India.

Varahagiri Venkata Giri *3-May-6920-Jul-69IndependentGiri was appointed as acting president following the death of Hussain. He resigned in a few months to take partin the presidential elections.
3Zakir Hussain13-May-673-May-69IndependentHussain was vice chancellor of the Aligarh Muslim University and a recipient of Padma Vibhushan and Bharat Ratna. He died before his term of office was ended.
2Sarvepalli Radhakrishnan13-May-6213-May-67IndependentRadhakrishnan was a prominent philosopher, writer, a Knight of the Realm and also held the position of vice chancellor of the Andhra University and Banaras Hindu University. Hewas also made a Knight of the Golden Army of Angels by Pope Paul VI.
1Rajendra Prasad26-Jan-5013-May-62Indian National CongressPrasad was the first President of independent India. He was also an independence activist of the Indian Independence Movement. Prasad was the only president to serve for two terms in office.

List of Presidents of India

Joke: Rajnikant For NAMO

Joke: Rajnikant For NAMO


Rajnikant For NAMO

Joke: Rajnikant For NAMO


Rajnikant : Mota Bhai… Bas Karu… Ya Aur Seat Chaahiye!!

Modi : Bas Chhote Bas Kar… Already Opposition Mein Koi Nahi Hai.. Ab Kya Padosi Desh ki seat Laayega Kya!?


Joke: Rajnikant For NAMO


Joke: Rajnikant For NAMO



Joke: Rajnikant For NAMO

Friday, May 16, 2014

Samsung Galaxy Mega KitKat update closing in fast

Google-Android

Samsung Galaxy Mega KitKat update closing in fast


Samsung Galaxy Mega 5.8 and Mega 6.3 have been launched last year with Android 4.2 Jelly Bean out of the box, and ever since the handsets have hit the shelves, Samsung has not launched any note-worthy updates for them. Fortunately, this does not mean that the Mega line-up will not be getting any updates in the future.

Android 4.4 is slowly but surely making its way across numerous smartphones, and in Samsung’s camp, there’s actually a lot of work to be done. This is the byproduct of launching smartphones across all market segments like there’s no tomorrow, and there are actually quite a lot of devices to keep track of when it comes down to KitKat’s availability.


The Samsung Galaxy Mega KitKat update (Android 4.4) is closing in fast. A leaked document seems to confirm that the Samsung Galaxy Mega models will all be getting updated to Android 4.4 (KitKat). Check out the details below.


galaxy-mega-kitkat


According to a recently leaked internal document listing the KitKat update status for a handful of Samsung smartphones, both the Samsung Galaxy Mega 5.8 and 6.3 are getting ready for the big day. The Android 4.4 KitKat update for these handsets is listed as being under “Testing” and the estimated time of arrival is set to June 2014.


The Samsung Galaxy Mega KitKat update is expected to bring a handful of new features to the table, including some of the latest TouchWiz goodies, such as Ultra Battery saving mode. The Mega series has been released last year as a budget-friendlier alternative to the Note series


Do any of you happen to own the Galaxy Mega 5.8 or 6.3? Are you excited for KitKat’s arrival? Don’t hesitate to share your thoughts below, and stick around for more



Samsung Galaxy Mega KitKat update closing in fast

Monday, May 12, 2014

Prism Interview Questions and Answers

Prism Interview Questions and Answers


What is Prism? 


Prism is the framework or the set of guidelines which is used to develop the WPF desktop application as well as the Silverlight Rich Internet applications(RIA). So it’s a kind of Design pattern to Develop the XMAL based application. It also used to develop the Windows 7 applications. Prism mainly helps to design the loosely coupled components which can be easily integrated with the other components of the overall application. Prism mainly used to build the composite applications which need various other components to be integrated.


Prism has RegionManager, EventAggregator and Commands all with the purpose of solving decoupling issues related to UI components.


Prism mainly guides of creating the applications using the Model-View-ViewModel (MVVM) model, Managed Extensibility Framework (MEF), and navigation in the application.


To use the Prism framework, we need to use their library called as Prism Library. So prism Library is the in-built set of components which can be used in developing the WPF and Silverlight applications.


What are objectives of Prism?


Following are the objectives of using Prism.


  • Create an application from modules that can be built, assembled, and, optionally, deployed by independent teams using WPF or Silverlight.

  • Minimize cross-team dependencies and allow teams to specialize in different areas, such as user interface (UI) design, business logic implementation, and infrastructure code development.

  • Use an architecture that promotes reusability across independent teams.

  • Increase the quality of applications by abstracting common services that are available to all the teams.

  • Incrementally integrate new capabilities.

What is Dependency Injection?


Dependency Injection is a practice where objects are designed in a manner where they receive instances of the objects from other pieces of code, instead of constructing them internally. This means that any object implementing the interface which is required by the object can be substituted in without changing the code, which simplifies testing, and improves decoupling.


Let’s assume that we have object dependency when an object ‘x’ uses an object ‘y’, we say that ‘x’ is dependent on ‘y’. Object dependency becomes a problem when object ‘x’ needs to use another object dynamically, object ‘z’, instead of ‘y’. Strong dependency mixes both object (Data) and relation (logic) in one place and result in tight coupling that render the code much harder to modify and adjust. Dependency injection allows objects to relate to each other but through an interface so that object ‘x’ will use interface ‘i’ while both ‘y’ & ‘z’ implement the interface ‘i’. This methodology allows the isolation between the implementation, creation, and logical dependency of an object.


The Prism Library includes the UnityBootstrapper and MefBootstrapper classes, which implement most of the functionality necessary to use either Unity or MEF as the dependency injection container in your application. In addition to the stages shown in the previous illustration, each bootstrapper adds some steps specific to its container.


What is an Event Aggregator?


EventAggregator is the utility service which contains the events and allows the decouple the publisher and subscriber so that they can be buildup independently. Decouple is primarily useful when a new module needs to be added or removed or modified. The new module can be added as per the event fired and defined in the shell.


The EventAggregator service is primarily a container for events that allow decoupling of publishers and subscribers so they can evolve independently. This decoupling is useful in modularized applications because new modules can be added that respond to events defined by the shell or, more likely, other modules.


In the Composite Application Library, EventAggregator allows subscribers or publishers to locate a specific EventBase. The event aggregator also allows for multiple publishers and multiple subscribers, as shown in figure below.

The EventAggregator class is offered as a service in the container and can be retrieved through the IEventAggregator interface. The event aggregator is responsible for locating or building events and for keeping a collection of the events in the system.


The real work of connecting publishers and subscribers is done by the CompositePresentationEvent class. This is the only implementation of the EventBase class that is included in the Composite Application Library. This class maintains the list of subscribers and handles event dispatching to the subscribers.


What is Shell?


The shell is the main window of the application where the primary user interface (UI) content is contained. The shell may be composed of multiple windows if desired, but most commonly it is just a single main window that contains multiple views. The shell may contain named regions where modules can specify the views that will appear. It may also define certain top-level UI elements, such as the main menu and toolbar. The shell defines the overall appearance for the application. It may define styles and borders that are present and visible in the shell layout itself, and it may also define styles, templates, and themes that get applied to the views that are plugged into the shell. 


What is view? 


Views are the composite portions of the user interface that are contained in the shell’s window(s). It is easiest to think about a view as a user control that defines a rectangular portion of the client area in the main window. However, views in the Composite Application Library do not have to be defined with a user control. You can use a Windows Presentation Foundation (WPF) data template to define a view that will be rendered based on the data in your model. A view could also share screen real estate with other views due to the rendering and compositing capabilities of WPF. In simple terms, a view is just a collection of user interface elements that define part of the rendering of the user interface. It is a unit of encapsulation for defining the separable portions of your UI.


What is Bootstrapper?


Bootstrapper is an utility in WPF engine which is mainly responsible for the initialization of the application by using the composite application library. By using the bootstrapper we can find out how the components of the application are wired up in the composite application library. The bootstrapper responsibility to create the Shell or main window. Composite application library has the default abstract class UnityBootstrapper which actually handles the initialization.


A bootstrapper is a class that is responsible for the initialization of an application built using the Prism Library. By using a bootstrapper, you have more control of how the Prism Library components are wired up to your application.


The Prism Library includes a default abstract Bootstrapper base class that can be specialized for use with any container. Many of the methods on the bootstrapper classes are virtual methods. You can override these methods as appropriate in your own custom bootstrapper implementation.


What are the basic stages of bootstrapping process? 


Basic stages of the bootstrapping process are as follows.


The Prism Library provides some additional base classes, derived from Bootstrapper, that have default implementations that are appropriate for most applications. The only stages left for your application bootstrapper to implement are creating and initializing the shell.


What is ILoggerFacade? 


ILoggerFacade is an interface used in Prism Framework for logging purpose.


The simplest approach to logging in Prism is to override the LoggerFacade property in your Bootstrapper. By overridding the LoggerFacade, you can pass in an instance of any Logger you want with any configuration needed as long as the logger implements the ILoggerFacade interface.


A simple Example is given below. 


using log4net;


using Microsoft.Practices.Prism.Logging;


namespace FsNoteMaster3



class Log4NetLogger : ILoggerFacade



#region Fields


 


// Member variables


private readonly ILog m_Logger = LogManager.GetLogger(typeof(Log4NetLogger));


 


#endregion


 


#region ILoggerFacade Members


 


/// <summary>


/// Writes a log message.


/// </summary>


/// <param name=”message”>The message to write.</param>


/// <param name=”category”>The message category.</param>


/// <param name=”priority”>Not used by Log4Net; pass Priority.None.</param>


public void Log(string message, Category category, Priority priority)



switch (category)



case Category.Debug:


m_Logger.Debug(message);


break;


case Category.Warn:


m_Logger.Warn(message);


break;


case Category.Exception:


m_Logger.Error(message);


break;


case Category.Info:


m_Logger.Info(message);


break;




 


#endregion




 What are Region and Region Managers?


In Prism framework, we define the region through XAML code and once a region is defined, automatically it will be registered with the RegionManager. Actually the Bootstrapper registers a service called the RegionManager at run time.


RegionManager is a dictionary where the key is name of the region. The value of the key is the reference of the IRegion interface. RegionAdapter is used to create the instance reference of the IRegion interface.


What are MEF and Unity?


Unity is mostly used for static dependencies and is more an “internal” technology, meaning outsiders do not need to know that unity is being used in the application. Unity is a IOC container. Use it to make your app more loosely coupled.


The MEF (Managed Extensibility Framework) is the new concept in .net 4.0. It is used to create the lightweight and extensible applications to create Managed Extensibility Framework. It is not only allows the extension but also reused within the application.


MEF should be used for dynamic dependencies, it is great at dynamically loading components and with the use of attributes it make creating application extensions or an application that can be extended by others easy and streamlined.


How to navigate to another page in WPF?


There is a class NavigationService which can be used for navigation of the WPF window:


this.NavigationService.GoForward();


OR



this.NavigationService.Navigate(“NextPage.xaml”)




Prism Interview Questions and Answers

ASP.NET Interview Questions And Answers Part-3

ASP.NET Interview Questions And Answers Part-3



How to identify which control caused Postback?

 



Below code will help you to identify the control which caused the postback.The name of the control which caused the postback will be set in__EVENTTARGET by __doPostBack JavaScript function before the form issubmitted.

 


string ctrlname = page.Request.Params.Get(“__EVENTTARGET”);

if (ctrlname != null && ctrlname != string.Empty)


return this.Page.FindControl(ctrlname);

 



How to Encrypt/Decrypt the web.config file in .NET?

 




public static void mEncryptWebConfig(string appPath, string protectedSection, stringdataProtectionProvider)


System.Configuration.Configuration webConfig =WebConfigurationManager.OpenWebConfiguration(appPath);

ConfigurationSection webConfigSection = webConfig.GetSection(protectedSection); if (!webConfigSection.SectionInformation.IsProtected)


webConfigSection.SectionInformation.ProtectSection(dataProtectionProvider); �

webConfig.Save();


public static void mDecryptWebConfig(string appPath, string protectedSection)


System.Configuration.Configuration webConfig =WebConfigurationManager.OpenWebConfiguration(appPath);

ConfigurationSection webConfigSection = webConfig.GetSection(protectedSection); if (webConfigSection.SectionInformation.IsProtected)


webConfigSection.SectionInformation.UnprotectSection();

webConfig.Save();

Can we set Master page dynamically at runtime?

 




Yes. Set the MasterPageFile property only during the PreInit page event—that is, before the runtime begins working on the request (since the rendering of the page with the master page occurs prior to the Init event)protected void Page_PreInit(object sender, EventArgs e)


MasterPageFile = “simple2.master”;

If you try to set the MasterPageFile property in Init or Load event handlers, an exception is raised.Note: The Master property represents the current instance of the master page object, is a read-only property, and can’t be set programmatically. The Master property is set by the runtime after loading the content of the file referenced by the MasterPageFile property.The above code needs to add in every page of the site. Instead, it is easy enough to add that code to a base page class that you can inherit from for you pages in the site. In case if you do not already have the base page, you can use the following web.config settings to have a base class without having to modify the existing aspx pages.<system.web>

<!– … –>

<pages pageBaseType=”MyWeb.UI.MyPageBase” />

<!– … –>

</system.web>
How to update web.config programatically?

 



Below is sample code to update web.config:protected void EditConfigButton_Click(object sender, EventArgs e)


Configuration objConfig = WebConfigurationManager.OpenWebConfiguration(“~”);

AppSettingsSection objAppsettings = (AppSettingsSection)objConfig.GetSection(“appSettings”); �

//Edit

if (objAppsettings != null)

objAppsettings.Settings["test"].Value = “newvalueFromCode”;

objConfig.Save();

 



How to implement singleton design pattern in C#?

 




The intent of the Singleton pattern as defined in Design Patterns is to “ensure a class has only one instance, and provide a global point of access to it”. The singleton pattern is a design pattern used to implement the mathematical concept of a singleton, by restricting the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. The concept is sometimes generalized to systems that operate more efficiently when only one object exists, or that restrict the instantiation to a certain number of objects (say, five). Some consider it an anti-pattern, judging that it is overused, introduces unnecessary limitations in situations where a sole instance of a class is not actually required, and introduces global state into an application. 

Below is sample implementation:


/// <summary>

/// Thread-safe singleton example created at first call

/// </summary>

public sealed class Singleton


private static readonly Singleton _instance = new Singleton();


private Singleton()


public static Singleton Instance


get


return _instance;



How to provide security in .NET web services?



 



Following are few authentication technics to secure a .NET Web Services
  1. Windows-Based Security
    1. Basic Windows Authentication

    2. Digest Windows Authentication

    3. Integrated Windows Authentication


  2. Custom Authentication
    1. Log-in Method

    2. SOAP Headers

    3. SOAP header with cookie

    4. SOAP Extensions

    5. SOAP extension with encryption


I listed three Windows-based and five custom authentication techniques for Web services. Obviously, there are many more permutations and variations on this theme. Table 1 lists the authentication options I discussed, and the main points to consider when choosing an authentication mechanism:


  • Is the password sent in clear text and therefore requires HTTPS?

  • What are the platform requirements on both the client and the server side?

  • When does authentication take place, on the first call only, or on every call? What are the throughput implications of that?

Table 1: Comparing Windows-based and custom authentication techniques for Web services.






































Authentication MethodPassword Sent in Clear TextRequires WindowsAuthenticate on First Call Only

Basic Authentication



Yes



No



Yes



Digest Authentication



No



No



Yes



Integrated Authentication



No



Client/Server



Yes



Log-in method



Yes



No



Yes



SOAP header



Yes



No



No



SOAP header with cookie



Yes



No



Yes



SOAP extension



Yes



Client/Server



Depends



SOAP extension with encryption



No



Client/Server



Depends




 



Following three patterns govern the ASP.NET Page Framework.
  1. Front Controller Pattern

  2. Page Controller Pattern

  3. Model View Controller Pattern

When ASP.NET determines which HttpHandler to pass a request to, it uses something similar to a Front Controller. Front Controller is characterized by a single handler for all requests (like System.Web.UI.Page). Once the request reaches the Page class, though, the Page Controller pattern takes over.


 


Within the ASP.NET implementation of Page Controller, there are elements of the Model View Controller pattern. Model View Controller separates the model (business objects, data, and processes) from the view (the display of information). The controller responds to user input and updates the model and view. Roughly speaking, an ASPX page represents the View while its codebehind file represents a hybrid Model-Controller. If you were to pull all business and data-related code out of the codebehind and leave only event handling code, this would turn the codebehind into a pure Controller while the new class containing the business logic would be the Model.

 




How can I create an non zero base indexed array?



 



Yes, It’s possible to create the arrays that have non-zero based index.You can dynamically create your own arrays by calling Array’s static CreateInstance method. There are several overloads of this method, but they all allow you to specify the type of the elements in the array, the number of dimensions in the array, the lower bounds of each dimension, and the number of elements in each dimension.But keep in mind that nonzero-based arrays are not CLS (Common Language Specification)-compliant.The following code demonstrates how to dynamically create a two-dimensional array of System.Decimal values.

 


public sealed class Program


public static void Main()


// We want a 2-dim array [2001..2010][1..4]

Int32[] lowerBounds = 2001, 1 ;

Int32[] lengths = 10, 4 ;

Decimal[,] quarterlyIncome =

(Decimal[,])Array.CreateInstance(typeof(Decimal), lengths, lowerBounds);


Console.WriteLine(“0,4 1, 9 2, 9 3, 9, 4, 9”,

“Year”, “Q1″, “Q2″, “Q3″, “Q4″);


Int32 firstYear = quarterlyIncome.GetLowerBound(0);

Int32 lastYear = quarterlyIncome.GetUpperBound(0);

Int32 firstQuarter = quarterlyIncome.GetLowerBound(1);

Int32 lastQuarter = quarterlyIncome.GetUpperBound(1);


for (Int32 year = firstYear; year <= lastYear; year++)


Console.Write(year + ” “);

for (Int32 quarter = firstQuarter; quarter <= lastQuarter; quarter++)


Console.Write(“0,9:c “, quarterlyIncome[year, quarter]);


Console.WriteLine();



The first dimension represents calendar years and goes from 2001 to 2010, inclusive. The second dimension represents quarters and goes from 1 to 4, inclusive.


 


Output:


 

 




Why can’t I serialize hashtables?



 




The thing about XML Serialization is that it’s not just about creating a stream of bytes. It’s also about creating an XML Schema that this stream of bytes would validate against. There’s no good way in XML Schema to represent a dictionary. This limitation is not only Hashtable, the XmlSerializer cannot process classes implementing the IDictionary interface due to the fact that a hashtable does not have a counterpart in the XSD type system. The only solution is to implement a custom hashtable that does not implement theIDictionary interface.
How form based authentication works in ASP.NET?

 


Forms authentication uses an authentication ticket that is created when a user logs on to a site, and then it tracks the user throughout the site. The forms authentication ticket is usually contained inside a cookie. However, ASP.NET version 2.0 supports cookieless forms authentication, which results in the ticket being passed in a query string.If the user requests a page that requires authenticated access and that user has not previously logged on to the site, then the user is redirected to a configured loginUrl under authentication section of web.config.This processing is handled by the FormsAuthenticationModule class, which is an HTTP module that participates in the regular ASP.NET page-processing cycle and intercepts every request to the website. If it fails to find valid authentication ticket, it will redirect to the logon page.The logon page prompts the user to supply credentials, typically a user name and password. These credentials are then passed to the server and validated against a user store, such as a SQL Server database or XML. After the user’s credentials are authenticated, we have to issue Forms authentication ticket before we redirected the user to the originally requested page. If you redirect the user without issuing Forms authentication ticket, FormsAuthenticationModule will again takes the user to login page as it fails to find valid ticket.

We can issue Forms authentication ticket in multiple ways beside on requirement


  1. Using FormsAuthentication.RedirectFromLoginPage

    [CODE=cs]

  2. if (objUserBLL.Validate(txtUser.Text, txtPassword.Text))


  3. FormsAuthentication.RedirectFromLoginPage(txtUser.Text, false);


  4. [/CODE]


    1. Using FormsAuthentication.SetAuthCookie

      [CODE=cs]

    2. if (objUserBLL.Validate(txtUser.Text, txtPassword.Text))


    3. string Role = objUserBLL.GetUserRole(txtUser.Text);

    4. if (Role.Equals(“JobSeeker”))


    5. FormsAuthentication.SetAuthCookie(txtUser.Text, false);

    6. Response.Redirect(“~/JobSeeker/Dashboard.aspx”);


    7. else if (Role.Equals(“Recruiter”))


    8. FormsAuthentication.SetAuthCookie(txtUser.Text, false);

    9. Response.Redirect(“~/Recruiter/Dashboard.aspx”);


    10. 20.


      [/CODE]



      ASP.NET Interview Questions And Answers Part-3

Wednesday, May 7, 2014

7 Pillars of ASP.NET - Interview Question

ASP Dot NET


7 Pillars of ASP.NET – Interview Question


If you are preparing for ASP.NET interview, must be ready for basic ASP.NET interview question “What are the Pillars of ASP.NET?” Pillars of ASP.NET means the fundamentals of ASP.NET like .NET Framework, CLS, CTS, MSIL, JIT, Object Oriented Concepts, Assemblies, DLLs, XCopy Deployment etc. I have listed down 7 Pillars of ASP.NET in detail.


7 Pillars of ASP.NET:


When ASP.NET was first released, there were seven key facts that differentiated it from previous Microsoft products and competing platforms. If you’re coming to ASP.NET from another web development platform, or you’re an old-hand .NET coder who has yet to try programming for the Web, these sections will quickly give you a bit of ASP.NET insight.


1: ASP.NET is integrated with the .NET Framework


The .NET Framework is divided into an almost painstaking collection of functional parts, with tens of thousands of types (the .NET term for classes, structures, interfaces, and other core programming ingredients).


2: ASP.NET is Compiled, Not Interpreted


ASP.NET applications, like all .NET applications, are always compiled. In fact, it’s impossible to execute C# or Visual Basic code without it being compiled first.


3: ASP.NET is Multilanguage


No matter what language you use, the code is compiled into MSIL. MSIL is a stepping stone for every managed application.


4: ASP.NET is Hosted by the Common Language Runtime


Perhaps the most important aspect of the ASP.NET engine is that it runs inside the runtime environment of the CLR. The whole of the .NET Framework—that is, all namespaces, applications, and classes—is referred to as managed code. Basic features of CLR are:


A) Automatic memory management and garbage collection

B) Type safety

C) Extensible metadata

D) Structured error handling

E) Multithreading


5: ASP.NET is Object-Oriented


ASP.NET is truly object oriented. Not only does your code have full access to all objects in the .NET Framework, but you can also exploit all the conventions of an OOP (object-oriented programming) environment.


6: ASP.NET supports all Browsers


ASP.NET addresses the problem of cross browser compatibility in a remarkably intelligent way. Although you can retrieve information about the client browser and its capabilities in an ASP.NET page, ASP.NET actually encourages developers to ignore these considerations and use a rich suite of web server controls. These server controls render their markup adaptively by taking the client’s capabilities into account.


7: ASP.NET is Easy to Deploy and Configure


Every installation of the .NET Framework provides the same core classes. As a result, deploying an ASP.NET application is relatively simple. For no-frills deployment, you simply need to copy all the files to a virtual directory on a production server (using an FTP program or even a command-line command like XCOPY).



7 Pillars of ASP.NET - Interview Question

WCF Interview Questions and Answers

WCF


WCF Interview Questions and Answers


Now a days mostly in every .NET project, WCF is used. So, every .NET developer must know at least basics of WCF. By keeping that in mind, I have tried to list down some basic WCF interview questions and answers which every .NET developer should know before going to the interview room. These WCF interview questions and answers cover basic concepts of WCF, SOA, difference between WCF and web services, need of WCF, endpoints in WCF like Address, Contracts and Bindings, types of Bindings in WCF, types of contracts in WCF, components of WCF, transport schemas in WCF, transactions in WCF, isolation levels in WCF, how to host WCF services, generating proxies for WCF services etc. So, lets have a look upon thes basic WCF interview questions and answers.
What is WCF?


WCF stands for Windows Communication Foundation. It is a Software development kit for developing services on Windows. WCF is introduced in .NET 3.0. in the System.ServiceModel namespace. WCF is based on basic concepts of Service oriented architecture (SOA)


WCF is part of .NET 3.0 and requires .NET 2.0, so it can only run on systems that support it. WCF 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 interoperate 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).


What is SOA (Service Oriented Architecture)?


Service-oriented architecture (SOA) is an evolution of distributed computing based on the request/reply design paradigm for synchronous and asynchronous applications. An application’s business logic or individual functions are modularized and presented as services for consumer/client applications.


What is endpoint in WCF service?


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.


Explain Address,Binding and contract for a WCF Service?


Address:Address defines where the service resides.

Binding:Binding defines how to communicate with the service.

Contract:Contract defines what is done by the service.


What are the various address format in WCF?

a)HTTP Address Format:–> http://localhost:

b)TCP Address Format:–> net.tcp://localhost:

c)MSMQ Address Format:–> net.msmq://localhost:


What are the types of binding available in WCF?


A binding is identified by the transport it supports and the encoding it uses. Transport may be HTTP,TCP etc and encoding may be text,binary etc. The popular types of binding may be as below:


a)BasicHttpBinding – 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.


b)NetTcpBinding – 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.


c)WSHttpBinding – 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.


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


e)NetPeerTcpBinding – 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.


What was the code name for WCF?


The code name of WCF was Indigo .

WCF is a unification of .NET framework communication technologies which unites the following technologies:-


  • NET remoting

  • MSMQ

  • Web services

  • COM+

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.


What are the types of contract available in WCF?


The main contracts are:

a)Service Contract Describes what operations the client can perform.

b)Operation Contract Defines the method inside Interface of Service.

c)Data Contract Defines what data types are passed

d)Message Contract Defines wheather a service can interact directly with messages


What are the various ways of hosting a WCF Service?


a)IIS

b)Self Hosting

c)WAS (Windows Activation Service)


What is Proxy and how to generate proxy for WCF Services?


The proxy is a CLR class that exposes a single CLR interface representing the service contract. The proxy provides the same operations as service’s contract, but also has additional methods for managing the proxy life cycle and the connection to the service. The proxy completely encapsulates every aspect of the service: its location, its implementation technology and runtime platform, and the communication transport.


Generating a Proxy class


a) The proxy can be generated using Visual Studio by right clicking Reference and clicking on Add Service Reference. This brings up the Add Service Reference dialog box, where you need to supply the base address of the service (or a base address and a MEX URI) and the namespace to contain the proxy.


b) Proxy can also be generated by using SvcUtil.exe command-line utility. We need to provide SvcUtil with the HTTP-GET address or the metadata exchange endpoint address and, optionally, with a proxy filename. The default proxy filename is output.cs but you can also use the /out switch to indicate a different name.


SvcUtil http://localhost/MyService/MyService.svc /out:Proxy.cs


When we are hosting in IIS and selecting a port other than port 80 (such as port 88), we must provide that port number as part of the base address:


SvcUtil http://localhost:88/MyService/MyService.svc /out:Proxy.cs

A proxy is a class by which a service client can Interact with the service.

By the use of proxy in the client application we are able to call the different methods exposed by the service


How can we create Proxy for the WCF Service?


We can create proxy using the tool svcutil.exe after creating the service.

We can use the following command at command line.

svcutil.exe *.wsdl *.xsd /language:C# /out:SampleProxy.cs /config:app.config


What is the difference between WCF Service and Web Service?


a)WCF Service supports both http and tcp protocol while webservice supports only http protocol.

b)WCF Service is more flexible than web service.


What is DataContract and ServiceContract?

Data represented by creating DataContract which expose the data which will be transefered /consumend from the service to its clients.

To write an operation on WCF,you have to write it as an interface,This interface contains the “Signature” of the methods tagged by ServiceContract attribute,and all methods signature will be impelemtned on this interface tagged with OperationContract attribute and to implement these serivce contract you have to create a class which implement the interface and the actual implementation will be on that class.


Code Below shows How to create a Service Contract:


Code:


[ServiceContract]

Public Interface IResource


[OperationContract]

Decimal GetTechnicalSkills(int ResourceID);



Class Resource: IResource


Decimal Get echnicalSkills ()


// Implementation of this method.


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.


What are 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.


Service Contract


There are two types of Service Contracts.

ServiceContract – This attribute is used to define the Interface.

OperationContract – This attribute is used to define the method inside Interface.



[ServiceContract]

interface IMyContract


[OperationContract]

string MyMethod( );


class MyService : IMyContract


public string MyMethod( )


return “Hello World”;



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.


There are two types of Data Contracts.

DataContract – attribute used to define the class

DataMember – attribute used to define the properties.



[DataContract]

class Contact


[DataMember]

public string FirstName;

[DataMember]

public string LastName;



If DataMember attributes are not specified for a properties in the class, that property can’t be passed to-from web service.


Fault contracts


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


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.


How to define a service as REST based service in WCF?


WCF 3.5 provides explicit support for RESTful communication using a new binding named WebHttpBinding.

The below code shows how to expose a RESTful service



[ServiceContract]

interface IStock


[OperationContract]

[WebGet]

int GetStock(string StockId);



By adding the WebGet Attribute, we can define a service as REST based service that can be accessible using HTTP GET operation.


What are different elements of WCF Srevices Client configuration file?


WCF Services client configuration file contains endpoint, address, binding and contract. A sample client config file looks like



<system.serviceModel>

<client>

<endpoint name = “MyEndpoint”

address  = “http://localhost:8000/MyService/”

binding  = “wsHttpBinding”

contract = “IMyContract”

/>

</client>

</system.serviceModel>



What is Transport and Message Reliability?


Transport reliability (such as the one offered by TCP) offers point-to-point guaranteed delivery at the network packet level, as well as guarantees the order of the packets. Transport reliability is not resilient to dropping network connections and a variety of other communication problems.


Message reliability deals with reliability at the message level independent of how many packets are required to deliver the message. Message reliability provides for end-to-end guaranteed delivery and order of messages, regardless of how many intermediaries are involved, and how many network hops are required to deliver the message from the client to the service.


How to deal with operation overloading while exposing the WCF services?


By default overload operations (methods) are not supported in WSDL based operation. However by using Name property of OperationContract attribute, we can deal with operation overloading scenario.


[ServiceContract]

interface ICalculator


[OperationContract(Name = "AddInt")]

int Add(int arg1,int arg2);

[OperationContract(Name = "AddDouble")]

double Add(double arg1,double arg2);

What are the advantages of hosting WCF Services in IIS as compared to self-hosting?


Automatic activation

IIS provides automatic activation that means the service is not necessary to be running in advance. When any message is received by the service it then launches and fulfills the request. But in case of self hosting the service should always be running.


Process recycling

If IIS finds that a service is not healthy that means if it has memory leaks etc, IIS recycles the process. Ok let us try to understand what is recycling in IIS process. For every browser instance, a worker process is spawned and the request is serviced. When the browser disconnects the worker, process stops and you lose all information. IIS also restarts the worker process. By default, the worker process is recycled at around 120 minutes. So why does IIS recycle. By restarting the worker process it ensures any bad code or memory leak do not cause issue to the whole system.


Self-hosting gives you full control like when to start a service host, stop and so on. But, you need to recycle the service and have to programmatically handle all the required things to make your service to work in critical errors. Sometimes, it may lead to server crash.


What is one-way operation?


IsOneWay equal to true ensures that the client does not have to wait for the response. So methods marked by IsOneWay to true should always return void. In this, the caller does not get anything in return so it is called as one-way communication. Code snippet for this is given below.


namespace OneWayOperationSample



[Service Contract()]


public inteface IOneWay



[OperationContract(IsOneWay = true)]


void OneWayMeth();



public class SvcOneWay : IOneWay



Public void OneWayMeth()



//Your Code





What is poison message?


A message is sent to a receiver that is malformed or causes some kind of exception and cannot be processed by a receiver.

This problem is known as poison message and it occurs while the message is in the queue and causing problems, no other messages can get processed, so in essence the poison message clogs up the queue


What is dead letters?


A message has a time-to-live that expires before the message is processed. This problem is called as dead letters.

In WCf and MSMQ, dead letter processing is controlled by the client-side of the wcf conversation. The client oe sender, specifies the time-to-live for the message and also specifies where the dead letter message is sent to.



WCF Interview Questions and Answers

Sunday, May 4, 2014

Difference between WPF and Silverlight

WPF

Difference between WPF and Silverlight


This article focuses on the difference between Silverlight and WPF technologies. Silverlight and Windows Presentation Foundation (WPF) both allow you to develop rich user experience applications based on XAML and the .NET Framework. For a period of time, Silverlight was called WPF/E, with the ‘E’ standing for ‘everywhere’. But there are some differences between the two technologies. Lets try to find out.


1. WPF is meant for developing rich applications for desktop platform while Silverlight is meant for developing rich browser based internet applications.


2. WPF is essentially the replacement to Winforms while Silverlight was introduced to compete with Adobe Flash.


3. Silverlight is a sub set of WPF in terms of features and functionality. WPF is based on the desktop CLR which is the full version of the CLR. Silverlight is based on a much smaller and more compact CLR which provides a great experience but does not have the full breadth of CLR features but only Core CLR features.


4. You can use Silverlight applications regardless of the operating system you use, while WPF applications are restricted to later versions of the Windows operating system. For a WPF browser application, you need the .NET Framework to be installed in the client location while for Silverlight, you need only the plug-in. So in other words, WPF browser applications are OS dependent while Silverlight is not. A Silverlight plug-in can run in OSs other than Windows while we all know the .NET Framework only runs in Windows.


5. WPF supports 3 types of routed events (direct, bubbling, and tunneling). Silverlight supports direct and bubbling only.



Difference between WPF and Silverlight

Saturday, May 3, 2014

Difference between WPF and Window Forms in .NET

WPF

Difference between WPF and Window Forms in .NET


There are a lot of differences between WPF and Window Forms. WinForms is past and WPF is the latest technology equipped with advanced features which Window Forms lack. WPF supports UI, media, documents, hardware acceleration, vector graphics, scalability to different form factors, interactive data visualization, and superior content readability. Lets have a look on the features and benefits that WPF provides over the Window Forms.


1. WPF is a Vector Graphics based UI Presentation Layer


WPF is a vector graphics based UI presentation layer where WinForms is not. By being vector based, it allows the presentation layer to smoothly scale UI elements to any size without distortion.


2. Enhanced Custom Controls Support


WPF is also a composable presentation system, which means that pretty much any UI element can be made up of any other UI element. This allows you to easily build up complex UI elements from simpler ones.


3. Enhanced DataBinding Support


WPF is also fully databinding aware, which means that you can bind any property of a UI element to a .NET object (or a property/method of an object), a property of another UI element, or data. Yes, WinForms supports databinding but in a much more limited way.


4. WPF is “skinable” or “themeable”


WPF is “skinable” or “themeable”, which means that as a developer you can use a list box because those are the behaviors you need but someone can “skin” it to look like something completely different.


Think of a list box of images. You want the content to actually be the image but you still want list box behaviors. This is completely trivial to do in WPF by simply using a listbox and changing the content presentation to contain an image rather than text.


5. Supports Window Forms


WPF does support Windows Forms and Windows Forms can be included in WPF project by adding dlls of Window Forms.


Conclusion:


WPF is a replacement for WinForms. What Window Forms can do, WPF can, but what WPF can do, Window Forms cannot do all.



Difference between WPF and Window Forms in .NET

WPF Interview Questions and Answers

WPF


WPF Interview Questions and Answers


In this aritcle on “WPF Interview Questions and Answers “, I will focus on very simple and basic WPF interview questions which a WPF developer should know. These WPF interview questions are based on general introduction of WPF, XAML, MVVM Pattern, Comparison of WPF and Silverlight, Layout Panels in WPF and WPF UserControls / CustomControls etc.


1. What is WPF?


The Windows Presentation Foundation is Microsofts next generation UI framework to create applications with a rich user experience. It is part of the .NET framework 3.0 and higher.


WPF combines application UIs, 2D graphics, 3D graphics, documents and multimedia into one single framework. Its vector based rendering engine uses hardware acceleration of modern graphic cards. This makes the UI faster, scalable and resolution independent.


2. What is XAML?


Extensible Application Markup Language, or XAML (pronounced “zammel”), is an XML-based markup language developed by Microsoft. XAML is the language behind the visual presentation of an application that you develop in Microsoft Expression Blend, just as HTML is the language behind the visual presentation of a Web page. Creating an application in Expression Blend means writing XAML code, either by hand or visually by working in the Design view of Expression Blend.


3. What is MVVM Pattren?


Model-View-ViewModel (MVVM) pattern splits the User Interface code into 3 conceptual parts – Model, View and ViewModel.


Model is a set of classes representing the data coming from the services or the database.


View is the code corresponding to the visual representation of the data the way it is seen and interacted with by the user.


ViewModel serves as the glue between the View and the Model. It wraps the data from the Model and makes it friendly for being presented and modified by the view. ViewModel also controls the View’s interactions with the rest of the application


4. What is the difference between MVVM and MVC patterns?


MVVM Model-View ViewModel is similar to MVC, Model-View Controller.


The controller is replaced with a View Model. The View Model sits below the UI layer. The View Model exposes the data and command objects that the view needs. You could think of this as a container object that view goes to to get its data and actions from. The View Model pulls its data from the model.


5. What are the similarities and differences between WPF and Silverlight?


Similarities between Silverlight and WPF


1. Silverlight and WPF both use XAML.

2. Silverlight and WPF share same syntax, code and libraries.


Difference between WPF and Silverlight


1. WPF is tool for writing full-featured desktop applications that run on Windows while Silverlight is for web application.


2. WPF competes with Windows Forms only for writing desktop applications while Silverlight competes with Flash, Java web apps etc.


6. What is the need of layout panels in WPF?


Layout of controls is critical to an applications usability. Arranging controls based on fixed pixel coordinates may work for an limited enviroment, but as soon as you want to use it on different screen resolutions or with different font sizes it will fail. WPF provides a rich set built-in layout panels that help you to avoid the common pitfalls.


7. What are the different types of layout panels in WPF?


There are mainly 5 types of layout panels in WPF. These are:


Grid Panel

Stack Panel

Dock Panel

Wrap Panel

Canvas Panel


8. How to create a User Control and then how to use it in a WPF application?


User Controls are commonly used in a WPF application. So you should know this concept and you should be able to write a simple program to show how usercontrols are created and used in WPF application. I am sharing a link which created and uses usercontrol in very simple manner. Have a look HERE:


9. What is the difference between UserControl and CustomControl in WPF?


UserControl (Composition)


Composes multiple existing controls into a reusable “group”

Consists of a XAML and a code behind file

Cannot be styled/templated

Derives from UserControl


CustomControl (Extending an existing control)


Extends an existing control with additional features

Consists of a code file and a default style in Themes/Generic.xaml

Can be styled/templated

The best approach to build a control library



WPF Interview Questions and Answers

WPF Difference between Static Resource and Dynamic Resource

WPF

WPF Difference between Static Resource and Dynamic Resource


There are lot of differences between Static Resource and Dynamic Resource in WPF. Lets try to understand them with the help of examples below:


  1. The major difference between static and dynamic resources is that static resource will evaluate the resource only once while dynamic resource will be evaluated every time the resource needed.


  2. Dynamic resource has more performance overhead than static resources because it look up for resources every time it requested or needed.


  3. Static resource is faster but it takes little more time to load page or window than dynamic resource because dynamic resources are loaded when you actually use them.

Example of Static and Dynamic Resources


Below example gives you clear picture about Static and Dynamic resource markup extension.


<Window.Resources>
<SolidColorBrush Color="LightBlue" x:Key="buttonBackground" />
</Window.Resources>
<StackPanel Name="stkPanel">
<Button Name="Button1" Content="Button1"
Background="StaticResource buttonBackground"/>
<Button Name="Button2" Content="Button2"
Background="DynamicResource buttonBackground"/>
<Button Name="Button3" Content="Button3"
Background="StaticResource buttonBackground"/>
</StackPanel>

void StaticAndDynamicResources_Loaded(object sender, RoutedEventArgs e)

stkPanel.Resources["buttonBackground"] = Brushes.Yellow;

Output
Static and Dynamic resrouces


As shown in above example, three buttons are using buttonBackground resource defined in windows.resources element. Button1 and Button3 are using static resource markup extension while button2 is using dynamic resource markup extension. After loading of my window, I have changed color of buttonBackground resource from Lightblue to Yellow in code behind. So when I run my application, Button2 will have yellow background and rest of the buttons will have LightBlue background. The reason behind for not changing background of Button1 and Button3 because both button uses static resource and static resource is loaded only once with application while button2 uses dynamic resource and it changes every time when it accessed.


Conclusion: The demerit of DynamicResource is that it reduces application performance because resources are retrieved every time they are used. The best practice is to use StaticResource until there is a specific reason to use DynamicResource.



WPF Difference between Static Resource and Dynamic Resource

Friday, May 2, 2014

Binding Modes in WPF

WPF


Binding Modes in WPF: TwoWay, OneWay, OneTime and OneWayToSource


The Mode attribute defines the binding mode that will determine how data flows between the source and the target. There are four types of binding modes in WPF:


  1. TwoWay Binding Mode

  2. OneWay Binding Mode

  3. OneTime Binding Mode

  4. OneWayToSource Binding Mode

    1. 1. TwoWay Binding Mode


      You have the view connected with its ViewModel, so every change you make in one of them is reflected into the other. To obtain that kind of behavior, you have to implement the interface INotifyPropertyChange in your ViewModel or using Dependency Properties, instead of normal CLR properties.The default however is two-way.


      This type of binding is appropriate for editable forms or other fully-interactive UI scenarios. Most properties default to OneWay binding, but some dependency properties (typically properties of user-editable controls such as the Text property of TextBox and the IsChecked property of CheckBox) default to TwoWay binding. A programmatic way to determine whether a dependency property binds one-way or two-way by default is to get the property metadata of the property using GetMetadata and then check the Boolean value of the BindsTwoWayByDefault property.


      2. OneWay Binding Mode


      In one way mode, data flows from the source to the target each time a change is made on the source (ViewModel). OneWay binding is the default binding mode for the TextBlock’s Text property and does not need to be specified.


      This type of binding is appropriate if the control being bound is implicitly read-only. For instance, you may bind to a source such as a stock ticker or perhaps your target property has no control interface provided for making changes, such as a data-bound background color of a table. If there is no need to monitor the changes of the target property, using the OneWay binding mode avoids the overhead of the TwoWay binding mode.


      3. OneTime Binding


      Like OneWay binding, OneTime binding sends data from the source to the target; however, it does this only when the application is started. When the DataContext changes, it does not listen for change notifications in the source.


      OneTime binding causes the source property to initialize the target property, but subsequent changes do not propagate. This means that if the data context undergoes a change or the object in the data context changes, then the change is not reflected in the target property. This type of binding is appropriate if you are using data where either a snapshot of the current state is appropriate to use or the data is truly static. This type of binding is also useful if you want to initialize your target property with some value from a source property and the data context is not known in advance. This is essentially a simpler form of OneWay binding that provides better performance in cases where the source value does not change.


      4. OneWayToSource Binding Mode


      OneWayToSource is the reverse of OneWay binding. Unlike OneWay and OneTime binding, OneWayToSource binding sends data from the target to the source.



      Binding Modes in WPF